Skip to content

Latest commit

 

History

History
64 lines (58 loc) · 864 Bytes

22. Unit 2 - Lesson 9.md

File metadata and controls

64 lines (58 loc) · 864 Bytes

Practice Programs - Control Statements

Q1.

n=int(input("n: "))
f1=0
f2=1
print(f1)
for i in range(n):
	print(f2)
	f3=f1+f2
	f1=f2
	f2=f3
	if (f2>n):
		break

Q2.

x=int(input("x: "))
y=int(input("y: "))

for n in range(x,y+1):
	if n>1:
		for i in range(2,n):
			if n%i==0:
				break
		else:
			print(n)

Q3.

n=int(input("n: "))
sum=0
c=n
temp=n
count=0
while n>0:
	count+=1
	n=n//10
while temp>0:
	d=temp%10
	sum=sum+d**count
	temp//=10
print("sum of powers:",sum)
if sum==c:
	print("armstrong number")
else:
	print("not armstrong number")

Q4.

# Type your program here...
c=input("ch: ")
if c=="A" or c=="a" or c=="e" or c=="E" or c=="i" or c=="I" or c=="o" or c=="O" or c=="u" or c=="U":
		print("letter and vowel")
elif c.isalpha()==True:
	print("letter and consonant")
else:
	print("not letter")