Python Programming Questions

 Python Programming Questions - [Basic SET-1]




1. Addition of Two Numbers

num1 = int(input("Enter First Number : "))
num2 = int(input("Enter Second Number : "))
result = num1+num2
print("The Addition Of ",num1," And ",num2," is : ",result)


Enter First Number : 35
Enter Second Number : 26
The Addition Of  35  And  26  is :  61 




2. Factorial of A Number
 
num = int(input(" Enter The Number : "))
fact = 1
if num==0:
    print(" Factorial of Zero = 1")
else:
    for i in range(1,num+1):
        fact = fact*i
    print(" Factorial of ",num,"Is  = ",fact)


 Enter The Number : 5
 Factorial of  5 Is  =  120 




3. Simple Interest

principal = float(input(" Enter The Principal Amount : "))
rate = float(input(" Enter The Rate Of Interest Per Annum : "))
time = float(input(" Enter The Time Period Is Years : "))
simpleInterest = (principal * rate * time)/100
amount =  principal + simpleInterest
print(" Simple Interest : ",simpleInterest)
print(" Total Amount : ",amount)


 Enter The Principal Amount : 10000
 Enter The Rate Of Interest Per Annum : 5
 Enter The Time Period Is Years : 5
 Simple Interest :  2500.0
 Total Amount :  12500.0 




4. Compound Interest

principal = float(input(" Enter The Principal Amount : "))
rate = float(input(" Enter The Rate Of Interest Per Annum : "))
time = float(input(" Enter The Time Period Is Years : "))
compundInterest = principal * (1 + rate/100)**time
amount =  principal + compundInterest
print(" Simple Interest : ",compundInterest)
print(" Total Amount : ",amount)



 Enter The Principal Amount : 1200
 Enter The Rate Of Interest Per Annum : 5.4
 Enter The Time Period Is Years : 2
 Compound Interest :  1333.0992
 Total Amount :  2533.0992




5. Armstrong Number

num = str(input(" Enter The Number : "))
length = len(num)
num1 = int(num)
temp = num1
sum = 0
while temp > 0 :
    rem = temp % 10
    sum = sum + pow(rem,length)
    temp = temp // 10

if sum == num1:
    print("Armstrong")
else:
    print("Not Armstrong ")
 


Enter The Number : 153
Armstrong


Enter The Number : 1634
Armstrong


Enter The Number : 152
Not Armstrong  



6. Sum of Digits of Entered Number  

num = int(input("Enter The Number : "))
temp = num
sum = 0
while temp > 0:
    rem = temp % 10
    sum = sum + rem
    temp = temp // 10

print("Sum of Digits Of Entered Number ",num,"Is : ",sum)



Enter The Number : 12345
Sum of Digits Of Entered Number  12345 Is :  15




7.  Palindrome Number

num = int(input(" Enter The Number : "))
temp = num
sum = 0
while temp > 0:
    rem = temp % 10
    sum = sum * 10 + rem
    temp = temp//10

if sum==num:
    print(" Palindrome ")
else:
    print(" Not Palindrome ")



 Enter The Number : 121
 Palindrome

 Enter The Number : 123
 Not Palindrome  




8. Reverse The Number

num = int(input(" Enter The Number : "))
temp = num
sum = 0
while temp > 0:
    rem = temp % 10
    sum = sum * 10 + rem
    temp = temp//10
print("Reverse of ",num,"Is : ",sum)
 


Enter The Number : 12345
Reverse of  12345 Is :  54321








 



Comments