Python Practical programs
Python Practical programs
Output:
Enter a number:55
Positive Number
Enter a number:0
Zero
Output:
Enter a number:25
25 is a odd number
Output:
Enter the integer:52145666
The reversed integer is:6664125
4. Write a Program to check Armstrong number program in python (For three digits)?
Sol)
num = int(input("Enter a number: "))
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output:
Enter a number: 153
153 is an Armstrong number
Sol)
Output:
Enter the number : 7
Multiplication Table of :
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
Sol)
n = int (input (“Enter the number for which the factorial needs to be calculated: “)
factorial = 1
if n < 0:
print (“Factorial cannot be calculated, non-integer input”)
elif n == 0:
print (“Factorial of the number is 1”)
else:
for i in range (1, n+1):
factorial = factorial *i
print (“Factorial of the given number is: “, factorial)
Output:
Enter the number for which the factorial needs to be calculated: 4
Factorial of the given number is: 24
Output:
How many terms? 7
Fibonacci sequence:
0
1
1
2
3
5
8
8. Write a Python program to find the largest number among the three input numbers
Sol)
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
Output:
Enter first number:110.5
Enter second Number:125.5
Enter third number:100
The largest number is:125.5
Output:
Enter a number: 15
15 is not a prime number
Enter a number: 17
17 is not a prime number
10. Write a Python Program to input marks of 4 subjects and display Total, Percentage, Result and
Grade. If student is fail (<40) in any subject then Result should be displayed as “FAIL” and Grade
should be displayed as "With Held**"
Sol)
m1=int(input("Enter Mark 1 : "))
m2=int(input("Enter Mark 2 : "))
m3=int(input("Enter Mark 3 : "))
m4=int(input("Enter Mark 4 : "))
total=(m1+m2+m3+m4)
per=total/4
if(m1 < 35 or m2 < 35 or m3 < 35 or m4 < 35):
print("Result : Fail")
print("Grade : With Held**")
else:
print("Result : Pass")
if(per>=90):
print("Grade : A+")
elif(per>=80 and per<90):
print("Grade : A")
elif(per>=70 and per<80):
print("Grade : B+")
elif(per>=60 and per<70):
print("Grade : B")
elif(per>=50 and per<60):
print("Grade : C")
print("Percentage : ",per)
Output:
Enter Mark 1:55
Enter Mark 2:45
Enter Mark 3:65
Enter Mark 4:55
Result: Pass
Grade: C
Percentage: 55