r/Python • • Aug 29 '22

Beginner Showcase Made a thing which takes your age and decides whether or not you’re allowed to use a website or something.

This is very basic, but it is my second project [First was the same, but without the years_from_13 thing and the elif age > 122 thing], and I’m pretty pleased with how it turned out.

age = int(input())

name = input()

years_from_13 = 13-age

if age < 13:

print(f"{name}, you are under 13 years of age. You are not old enough to use this - Come back in {years_from_13} years time.")

elif age > 122:

print(f"{name}, did you know that the oldest known person lived to just under 122.5 years old? It seems like you didn't. Nice try, though.")

else:

print(f"Welcome, {name}.")
0 Upvotes

4 comments sorted by

9

u/aaronlyy Aug 29 '22

Good job, now you could try to validate if entered input is actually a number or something else and will crash your code.

1

u/[deleted] Aug 29 '22

The code doesn’t work if it isn’t a number. I tried to make sure of that.

1

u/trasnsposed_thistle Aug 29 '22 edited Aug 29 '22

The point is - it won't work but it will raise en exception and crash if the user enters "Try me m8" when asked about age.

aaronlyy meant that you could try to make sure the code is prepared to handle inputs other than numerical values (for instance: by placing the age = int(input()) inside a try-except block)

1

u/[deleted] Aug 29 '22

Cool, now add something else. And keep building, problem solving is hard but extremely rewarding.