Python program to find the max of 2 numbers (using if)

a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
if a>b:
print(a,'is the greater number')
elif b>a:
print(b,'is the greater number')
else:
print('Both the numbers are same')

Python program to find the max of 2 numbers (using function)

a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
if a==b:
print('Both the numbers are same')
else:
print(max(a,b),'is the greater number')

Python program to find the max of 2 numbers (using lambda function)

A lambda is an anonymous function, and it takes any number of arguments. But the expression is only one.

a=int(input("Enter first number: "))
b=int(input("Enter second number: "))

if a==b:
print('Both the numbers are same')
else:
big_num = lambda a,b:a if a > b else b
print(big_num(a,b),' is the greater number')

Python program to find the largest of 3 numbers


a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
if a==b==c:
print('Same number')
elif a>b>c:
print(a,"is the largest number")
elif b>a>c:
print(b,"is the largest number")
elif c>b>a:
print(b,"is the largest number")

Python program to find the largest of 3 numbers (using user defined function)

def max_of_three(a, b, c):
if (a>b) and (b>c):
largest = a
elif (b>a) and (b>c):
largest = b
else:
largest = c
return largest
print(max_of_three(10,30,20))
print(max_of_three(23,7,12))

Python program to find the largest of 3 numbers (using max function)

a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))

if a==b==c:
print('Same number')
else:
print(max(a,b,c),'is the largest number')

Print multiplication table of a given number

n=int(input('Enter a number to print the multiplication table:'))
for i in range(1,11):
print(n,'*',i,'=', n*i)

Print multiplication table of a given number (horizontal output)

n=int(input('Enter a number to print the multiplication table:'))
for i in range(1,11):
print(n*i, end=' ')

Print multiplication table in a given range (horizontal output)

x=int(input('Enter the minimum value of the range:'))
y=int(input('Enter the maximum value of the range:'))

for i in range(x,y+1):
for j in range(1,11):
print(i*j, end='\t')
print()

Print multiplication table in a given range (side by side)

x=int(input('Enter the minimum value of the range:'))
y=int(input('Enter the maximum value of the range:'))

for i in range(1,11):
for j in range(x,y+1):
print(i*j,end='\t')
print()

Leave A Comment

All fields marked with an asterisk (*) are required

Verified by MonsterInsights