Hello I am a Python fresher and I wanna use the feature "return" just like in c++. You know that if I "return" in c++, the whole main function will stop, but it seems that in Python "return" can only be used in function. I tried to use "exit" to replace it but I don't know why it still executed the "except" part. Is there anything wrong with my code? Thank you very much!
name=input("Please input your name? ")
print("Hello,", name)
year=input("Please input your birth year? ")
try:
age=2007-int(year)
if age <= 25:
print("Welcome home! You have 5 chances to win the prize. ")
for i in range (1, 5):
luckynumber=input("Please input an random number? ")
if int(luckynumber) == 66:
print("Congratulation! Fist Prize!")
exit(0)
elif int(luckynumber) == 88:
print("Not bad! Second Prize! ")
exit(0)
else:
print("Best luck for next turn!")
print("Sorry, you didn't win. ")
else:
print("Get out!")
except:
print("Your birth-year or luckynumber must be an integer")