I am doing a multi part lab and its instructions are:
You will define a function named main() (LO 1)
You will get input in the main function and pass it to the following functions: (LO 2)
a. milesToKm()
b. FahToCel()
c. GalToLit()
d. PoundsToKg()
e. InchesToCm()
Each function will require that you have a local variable to store the result of the calculation. This result will then be displayed using the print statement from within the function (LO 1, 2, 3)
This is what I have so far:
def main():
terminate=False
if terminate == True:
print('Program has been terminated\n')
while terminate==False:
miles_tries=0
mile_value=float(input('Roger, Enter a number of miles you wish to convert: '))
while miles_tries <2 and mile_value<0:
print('Roger, the value of the miles cannot be a negative number')
mile_value=float(input('Roger, Enter a number of miles you wish to convert: '))
miles_tries+=1
if miles_tries >=2 and mile_value<0:
terminate=True
else:
milesToKm(mile_value)
temp_tries=0
temp_value=float(input('Roger, Enter a temperature you wish to convert: '))
while temp_tries <2 and temp_value>1000:
print('Roger, the value of the temperature cannot be greater than 1000')
temp_value=float(input('Roger, Enter a number of degrees fahrenheit you wish to convert: '))
temp_tries+=1
if temp_tries >=2 and temp_value>1000:
terminate=True
else:
FahToCel(temp_value)
gallon_tries=0
gallon_value=float(input('Roger, Enter a number of gallons you wish to convert: '))
while gallon_tries <2 and gallon_value<0:
print('Roger, the value of the gallons cannot be a negative number')
gallon_value=float(input('Roger, Enter a number of gallons you wish to convert: '))
gallon_tries+=1
if gallon_tries >=2 and gallon_value<0:
terminate=True
else:
GalToLit(gallon_value)
pound_tries=0
pound_value=float(input('Roger, Enter a number of pounds you wish to convert: '))
while pound_tries <2 and pound_value<0:
print('Roger, the value of the pounds cannot be a negative number')
pound_value=float(input('Roger, Enter a number of pounds you wish to convert: '))
pound_tries+=1
if pound_tries >=2 and pound_value<0:
terminate=True
else:
PoundToKg(pound_value)
inches_tries=0
inches_value=float(input('Roger, Enter a number of inches you wish to convert: '))
while inches_tries <2 and inches_value<0:
print('Roger, the value of the inches cannot be a negative number')
inches_value=float(input('Roger, Enter a number of inches you wish to convert: '))
inches_tries+=1
if inches_tries >=2 and inches_value<0:
terminate=True
else:
InchesToCm(inches_value)
def milesToKm(value):
km=int(value)*1.6
print("Roger,", value, " miles is equal to ", km, " kilometers\n")
def FahToCel(value):
c=(int(value)-32)*5/9
print("Roger, ",value, " degrees fahrenheit is equal to ", c, " degrees celsius.\n")
def GalToLit(value):
gal=int(value)*3.9
print("Roger, ",value, " gallons is equal to ", gal, " liters.\n")
def PoundToKg(value):
kg=int(value)*.45
print("Roger, ",value, " Pounds is equal to ", kg, " kilograms\n")
def InchesToCm(value):
cm=int(value)*2.54
print("Roger, ",value, " inches is equal to ", cm, " centimeters\n")
main()
print('Have a good day')
I want the entire program to end if the user types in a negative number more than three times for any of the inputs, or if they type a value greater than 100 more than three times for the temperature conversion. It doesn't seem to be working right now. How would I end the whole program LOGICALLY if the user inputs a negative number more than 3 times?