Professional Documents
Culture Documents
Exp2 - 48 Py
Exp2 - 48 Py
Exp2 - 48 Py
num=int(input("Enter the number: "))
sum=0
n1=len(str(num))
temp=num
while temp>0:
digit=temp%10
sum+=digit**n1
temp//=10
if num==sum:
print(num,"Is an armstrong number.")
else:
print(num,"Is not an armstrong number.")
n=int(input("Enter the number: "))
factorial=1
if n>=1:
for i in range(1,n+1):
factorial=factorial*i
print("Factorial of given number is: ",factorial)
year=int(input("Enter the year: "))
if(year%400==0):
print("%d is a leap year."%year)
elif(year%100==0):
print("%d is not a leap year."%year)
elif(year%4==0):
print("%d is a leap year."%year)
else:
print("%d is not a leap year"%year)
1. using if...elif...else
num=float(input("Enter the number: "))
if num>0:
print("POsitive number.")
elif num==0:
print("Zero.")
else:
print("Negative number.")
Negative number.
num=float(input("Enter the number: "))
if num>0:
if num==0:
print("Zero.")
else:
print("Positive number.")
else:
print("Negative number.")
Positive number.
Questions of curiosity:
1.Write a python program to find those numbers which are divisible by 7 and multiple of
5,between 2500 and 3600(both included).
n1=[]
for x in range(2500,3601):
if(x%7==0) and (x%5==0):
n1.append(str(x))
print(','.join(n1))
2520
2520,2555
2520,2555,2590
2520,2555,2590,2625
2520,2555,2590,2625,2660
2520,2555,2590,2625,2660,2695
2520,2555,2590,2625,2660,2695,2730
2520,2555,2590,2625,2660,2695,2730,2765
2520,2555,2590,2625,2660,2695,2730,2765,2800
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2520,2555,2590,2625,2660,2695,2730,2765,2800,2835,2870,2905,2940,2975,3010,3045,3080,
2.Write a python program to count the number of even and odd numbers from a series of
numbers.Sample numbers: numbers=(1,2,3,4,5,6,7,8,9),Expected output: Number of even
numbers: 5, Number of odd numbers: 4
numbers=(31,22,23,24,45,65,44,53,356,65,47,86,63,74)
count_odd=0;
count_even=0;
for x in numbers:
if not x%2:
count_even+=1
else:
count_odd+=1
print("Number of even numbers: ",count_even)
print("Number of odd numbers: ",count_odd)
3.Write a python program that prints all the numbers from 0 to 6 except 3 and 6. Note:Use
'continue' statement. Expected Output: 0 1 2 4 5
for x in range(6):
if(x==3 or x==6):
continue
print(x,end='')
print("\n")