Categories:Viewed: 7 - Published at: a few seconds ago

Write a python program using while loop to reverse a number and print the reversed number

Number = int(input("Please Enter any Number: "))    
Reverse = 0    
while(Number > 0):    
    Reminder = Number %10    
    Reverse = (Reverse *10) + Reminder    
    Number = Number //10    

print("\n Reverse of entered number is = %d" %Reverse)  

Write a python program to take year as input and check if it is a leap year or not

year = int(input("Enter a year: "))  
if (year % 4) == 0:  
   if (year % 100) == 0:  
       if (year % 400) == 0:  
           print(f"{year} is a leap year")  
       else:  
           print(f"{year} is not a leap year")  
   else:  
       print(f"{year} is a leap year")  
else:  
   print(f"{year} is not a leap year")

Write a python program to input a number to test and print if it is a prime number

num = int(input("Enter number :"))
lim = int(num/2) + 1
for i in range(2,lim):
    rem = num % i
    if rem == 0 :
        print(num,"is not a prime number")
        break
else:
    print(num,"is a prime number")

Write a python program to input a string from user and convert input string into all upper case and print the result

string = input("Please Enter your Own String : ")

string1 = string.upper()

print("\nOriginal String in Lowercase  =  ", string)
print("The Given String in Uppercase =  ", string1)

Write a python program to input a string from user and count vowels in a string and print the output

str1 = input("Please Enter Your Own String : ")
vowels = 0

for i in str1:
    if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' or i == 'A'
       or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
        vowels = vowels + 1

print("Total Number of Vowels in this String = ", vowels)

Write a python program to input a Number N from user and print Odd Numbers from 1 to N

maximum = int(input(" Please Enter any Maximum Value : "))

for number in range(1, maximum + 1):
    if(number % 2 != 0):
        print("{0}".format(number))

Write a python program to input a Number N from user and print Even Numbers from 1 to N

maximum = int(input(" Please Enter the Maximum Value : "))

for number in range(1, maximum+1):
    if(number % 2 == 0):
        print("{0}".format(number))

Write a python program to input two numbers from user and add two Numbers and print the result

number1 = input(" Please Enter the First Number: ")
number2 = input(" Please Enter the second number: ")

sum = float(number1) + float(number2)
print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))

Write a python program that takes two integers as input and check if the first number is divisible by other

num1 = int(input("Enter first number :"))
num2 = int(input("Enter second number :"))
remainder  = num1 % num2
if remainder == 0:
    print(num1 ," is divisible by ",num2)
else :
    print(num1 ," is not divisible by ",num2)

Write a python program to print the table of input integer

num = int(input("Please enter a number "))
for a in range(1,11):
    print(num , 'x' , a , '=' ,num*a)

Write a python program to print the factorial of number

num = int(input("Please enter a number "))
fact = 1
a = 1
while a <= num :
    fact *= a
    a += 1
print("The factorial of ",num, " is ",fact)

Write a python program which takes 3 numbers as input and to print largest of three numbers using elif statement

a = float(input("Please Enter the First value: "))
b = float(input("Please Enter the First value: "))
c = float(input("Please Enter the First value: "))

if (a > b and a > c):
          print("{0} is Greater Than both {1} and {2}". format(a, b, c))
elif (b > a and b > c):
          print("{0} is Greater Than both {1} and {2}". format(b, a, c))
elif (c > a and c > b):
          print("{0} is Greater Than both {1} and {2}". format(c, a, b))
else:
          print("Either any two values or all the three values are equal")

Write a python program which takes input a number N and print first N elements of fibonacci series

N = int(input("Please enter a number "))
first = 0
second = 1
print(first)
print(second)
for a in range(1,N-1):
    third = first + second
    print(third)
    first,second = second , third