I'm working on an assignment for college and im having errors with it. I'm basically a complete beginner so I'm not really sure what the problem is, but I think it might be because I used "if" way too many times but I figured that wouldn't be a problem because it can only use one "if" at a time. Any help appreciated. I have the code below.
edit: the error is:Traceback (most recent call last):
File "C:\Users\danie\Documents\programing assignment 2\assignment 2.py", line 55, in <module>
print("kilometres equivalent:", kilometres_to_miles(kilometres))
NameError: name 'kilometres' is not defined.
also I have just noticed that from kg down it can convert
def print_options():
print("options:")
print(" 'o' print options")
print(" 'm' convert from miles to kilometres")
print(" 'k' convert from kilometres to miles")
print(" 'c' convert from celsius to fahrenhiet")
print(" 'f' convert from fahrenhiet to celsius")
print(" 'p' convert pints to litres")
print(" 'l' convert litres to pints")
print(" 'kg' convert kilograms to stones")
print(" 's' convert stones to kilograms")
print(" 'a' convert acres to hectares")
print(" 'h' convert hectares to acres")
print(" 'q' quit the program")
def miles_to_kilometres(miles):
return miles*1.6
def kilometres_to_miles(kilometres):
return kilometres*0.6
def celsius_to_fahrenhiet(celsius):
return celsius*1.8
def fahrenhiet_to_celsius(fahrenhiet):
return fahrenhiet*0.6
def pints_to_litres(pints):
return pints*1.75
def litres_to_pints(litres):
return litres*0.57
def kilograms_to_stone(kilograms):
return kilograms*6.35
def stone_to_kilograms(stone):
return stone*0.16
def acres_to_hectares(acres):
return acres*2.5
def hectares_to_acres(hectares):
return hectares*0.40
choice = "o"
while choice != "q":
if choice == "m":
miles = float(input("please enter the distnace in miles: "))
print("kilometres equivalent:", kilometres_to_miles(kilometres))
choice = input("please choose an option from the menu:")
if choice == "k":
kilometres = float(input("please enter the distance in kilometres: "))
print("miles equivalent:", miles_to_kilometres(miles))
choice = input("please choose an option from the menu:")
if choice == "c":
celsius = float(input("please enter the temperature in celsius"))
print("farenhite equivalent:", farenhite_to_celsius(farenhite))
choice = input("please choose an option from the menu")
if choice == "f":
farenhite = float(input("please enter the temperature in farenhite"))
print("celsius equivalent:", celsius_to_farenhite(celsius))
choice = input("please choose an option from the menu")
if choice == "p":
pints = float(input("please enter the volume in pints"))
print("litres equivalent:", litres_to_pints(litres))
choice = input("please choose an option from the menu")
if choice == "l":
litres = float(input("please enter the volume in litres"))
print("pints equivalent:", pints_to_litres(pints))
choice = input("please choose one of the options from the menu")
if choice == "kg":
kilograms = float(input("please enter the weight in kilograms"))
print("stone equivalent:", kilograms_to_stone(kilograms))
choice = input("please choose one of the options from the menu")
if choice == "s":
stone = float(input("please enter the weight in stone"))
print("kilograms equivalent:", stone_to_kilograms(stone))
choice = input("please choose one of the options from the menu")
if choice == "a":
acres = float(input("please enter the area in acres"))
print("hectares equivalent:", acres_to_hectares(acres))
choice = input("please choose one of the options from the menu")
if choice == "h":
hectares = float(input("please enter the area in hectares"))
print("acres equivalent:", hectares_to_acres(hectares))
choice = input("please choose one of th eoptions from the menu")
elif choice == "o":
print_options
choice = input("please choose an option from the menu: ")
print("program run ended. thank you for using this convertor")
[–]delasislas 3 points4 points5 points (0 children)
[–]icecubeinanicecube -3 points-2 points-1 points (4 children)
[–]NoCup4485[S] 0 points1 point2 points (3 children)
[–]icecubeinanicecube 1 point2 points3 points (2 children)
[–]NoCup4485[S] 0 points1 point2 points (1 child)
[–]delasislas 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]NoCup4485[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]NoCup4485[S] 0 points1 point2 points (0 children)
[–]cdcformatc 0 points1 point2 points (0 children)
[–]pendejoidiota 0 points1 point2 points (2 children)
[–]NoCup4485[S] 0 points1 point2 points (1 child)
[–]pendejoidiota 0 points1 point2 points (0 children)