ok so im making a program that finds postage rate according to its weight and category. The category is standard for weights under 50g and other for over 50g. If the user enters a weight out of its category it will say error and close. and it only works for canada and usa which the program will prompt
here is what i have so far:
#
#
def main():
inputok = False
usa = True
canada = False
country = input("Please choose postage for canada or usa: ")
if country != "canada" and country != "usa":
print(" This is not a valid country! ")
if country == "usa":
size = input("Is this standard or other letter size? ")
if size == "standard":
weight = int(input("Please enter the weight: "))
if weight > 0 and weight <= 30:
print("The letter will be standard andcost $0.98. ")
elif weight > 30 and weight <= 50:
print("The letter will be standard andcost $1.18 ")
elif weight > 50 and weight <= 100 :
print("The letter will be standard and cost $1.96. ")
if size == "other":
weight = int(input("Please enter the weight: "))
if weight > 100 and weight <= 200:
print("This letter will be under size category other letter and it will cost $3.40. ")
elif weight > 0 and weight <= 100:
print(" Not valid")
elif weight > 30 and weight <= 50:
print("This letter will be under size category other letter and it will cost $6.80. ")
if country == "canada":
size = input("Is this standard or other letter size? ")
if size == "standard":
weight = int(input("Please enter the weight: "))
if weight > 0 and weight <= 30:
print("The letter will be standard andcost $0.54. ")
elif weight > 30 and weight <= 50:
print("The letter will be standard andcost $0.98. ")
elif weight <= 100:
print("The letter will be standard and cost $1.18. ")
elif weight > 100 and weight <= 500:
print(" Not valid")
return
if size == "other":
weight = int(input("Please enter the weight: "))
if weight > 100 and weight <= 200:
print("This letter will be under size category other letter and it will cost $1.96. ")
elif weight > 200 and weight <= 500:
print("This letter will be under size category other letter and it will cost $2.75. ")
main()
and here is my problem when i put other for the size
Traceback (most recent call last):
File "C:/Program Files (x86)/22.py", line 51, in <module>
main()
File "C:/Program Files (x86)/22.py", line 18, in main
if weight > 0 and weight <= 30:
UnboundLocalError: local variable 'weight' referenced before assignment