Function:
question 1: convert inche-mm
question 2: convert Celsius-Fahrenheit
question 3: return max of 3 nums
question 4: input and combine title+first+last
question 5: car_rental (dayrate, #days) get discount with >5 dayes , >10 days
I want very simple code for them
def inch_to_mm(inch):
'''
convert inche-mm
'''
return inch * 25.4
def cels_to_fahr(cels):
'''
convert Celsius-Fahrenheit
'''
return (cels*9/5) + 32
def max_of_nums(num1, num2, num3):
'''
return max of 3 nums
'''
if num1 > num2:
if num1 > num3:
return num1
else:
return num3
elif num2 > num3:
return num2
else:
return num3
def input_and_combain():
'''
input and combine title+first+last
'''
title = input("title: ")
first = input("first: ")
last = input("last: ")
return title + " " + first + " " + last
def car_rental(dayrate, days):
'''
car_rental (dayrate, #days) get discount
with >5 days - 5% , >10 days - 10%
'''
rent = dayrate * days
if days >= 10:
rent -= 0.1*rent
elif days >= 5:
rent -= 0.05*rent
return rent
#Testing functions
print(max_of_nums(2,1,2))
print(inch_to_mm(10))
print(cels_to_fahr(0))
print(input_and_combain())
print(car_rental(15,20))
Comments
Leave a comment