Python program to print largest among 3
# Python program to find the largest number among the three input numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
python program to print pttern *,**,***.
def pypart(n):
if n==0:
return
else:
pypart(n-1)
print("* "*n)
# Driver Code
n = 5
pypart(n)
PYTHON PROGRAM TO PRINT ODD OR EVEN
# Python program to check if the input number is odd or even.
# A number is even if division by 2 gives a remainder of 0.
# If the remainder is 1, it is an odd number.
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
Python program to check vowels or not
# taking user input
ch = input("Enter a character: ")
if(ch=='A' or ch=='a' or ch=='E' or ch =='e'
or ch=='I'
or ch=='i' or ch=='O' or ch=='o' or ch=='U'
or ch=='u'):
print(ch, "is a Vowel")
else:
print(ch, "is a Consonant")
Python Program to Print First 10
Natural Numbers
print("====The First 10 Natural Numbers====")
for i in range(1, 11):
print(i)
Input a list of numbers and find the smallest
and largest number from the list Python
Program
#create empty list
mylist = []
number = int(input('How many elements to put in List: '))
for n in range(number):
element = int(input('Enter element '))
mylist.append(element)
print("Maximum element in the list is :", max(mylist))
print("Minimum element in the list is :", min(mylist))
Python Program to Find Largest
and Smallest Item in a Tuple
# Tuple Largest and Smallest Item
lgsmTuple = (78, 67, 44, 9, 34, 88, 11, 122, 23, 19)
print("Tuple Items = ", lgsmTuple)
print("Largest Item in lgsmTuple Tuple = ", max(lgsmTuple))
print("Smallest Item in lgsmTuple Tuple = ", min(lgsmTuple))
Python Program to Print the
Fibonacci sequence
# Program to display the Fibonacci sequence up to n-th term
nterms = int(input("How many terms? "))
# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
Python Program to Check if a Number is
Palindrome or Not
Palindrome – reverse is also same – 121 , rev= 121
num = 1221
temp = num
reverse = 0
while temp > 0:
remainder = temp % 10
reverse = (reverse * 10) + remainder
temp = temp // 10
if num == reverse:
print('Palindrome')
else:
print("Not Palindrome")
Another methiod
num = 1234
reverse = int(str(num)[::-1])
if num == reverse:
print('Palindrome')
else:
print("Not Palindrome")