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

Woah, what version are you using. There's no indents.

Please use code tag so indents work.
Always read sticky post in top off a forum.

3.2 or somethin uhh i think its cuase i jus pasted so it didnt indent

So please, go on, repost your code with appropriate tags around it

But one quick point is that if the letter is not standard, weight is tested but not yet defined (this is the translation of your error message)
Why do you test the size to allow the input of the weight : you ask the same question in both case. Don't test size.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.