#Python program to find the max of 2 nmbers (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 (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
#---------- end of function ------------
print(max_of_three(10,30,20))
print(max_of_three(23,7,12))
# Python program to find the largest (using max function)
#number inputs
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
#check if the numbers are same
if a==b==c:
print('Same number')
else:
#print largest using max function
print(max(a,b,c),'is the largest number')
#Print multiplication table
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 (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 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()
#print the first letter of each of the words using list comprehension
#List comprehension is used to perform some operation for every element
# or select a subset of elements that meet a condition.
s='Python is a programming language'
my_list= [word[0] for word in s.split()]
print(my_list)
#print the first letter of each of the words
s='Python is a programming language'
my_list = []
for word in s.split():
my_list.append(word[0])
print(my_list)