Flow Control Programs
Flow Control Programs
1. Write a program for print given number is prime number or not using for loop and
require 1 to given number odd and even number
Solution :
n = int(input("enter the number : "))
c=0
for i in range (1,n):
if n % i ==0:
c = c+1
break
if c==2:
print (" The Given Number is Prime number")
else:
print (" The Given Number is not Prime number")
for c in range(n):
if c % 2 == 0:
print(c,"-even")
else:
print(c,"-odd")
2. Write a program print Fibonacci series and sum the even numbers. Fibonacci series
is
1,2,3,5,8,13,21,34,55
Solution:
n = int(input("enter the n value :"))
f=0
s=1
sum=0
for i in range(0,n):
n=f+s
print(n)
f=s
s=n
if n%2==0:
sum+=n
print("The sum of even numbers : ",sum)
3. Write a program to print n prime numbers and display the sum of prime numbers.
Solution:
4. Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3,
1/4, . . ,1/n
Solution:
Solution:
sum = 0
while True:
n = int(input("enter the Number : "))
if n ==-1:
break
else:
sum=sum+n
print("the sum is :",sum)
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Solution:
ch='A'
n = int(input("enter the number :"))
for i in range(1,n):
print(ch)
ch=chr(ord(ch)+1)
7. Write a program to display the following sequence.
AB
ABC
ABCD
ABCDE
Solution:
BC
D E F
G H I
KLMNO
Solution:
ch='A'
n= int(input("enter the number of rows : "))
for i in range(1,n):
for j in range(1,i+1):
print(ch)
ch=chr(ord(ch)+1)
print("")
9. Write a program that takes input string user and display that string if string
contains at least one Uppercase character, one Lowercase character and one digit.
Solution:
Solution: