Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python The Problem

Can someone update this challenge? The links in the teacher's notes lead to a whole track and not a specific video.

Nothing to add outside of subject ^

1 Answer

jmac pd
jmac pd
11,490 Points

Put this as an answer instead of a comment =)

You'll want to create a function to get the name and age. This way you can try and except the value error if they don't enter an "int" value type and then return the values

def ask_name():
    while True:
        try:
            age = int(input('please enter your age: '))
            year = int(input('what year were you born: '))
            return age, year
        except ValueError:
            print("please enter a number")

now if you can call this function anytime to ask the name.

age, year = ask_name()
print(age)
print(year)

you could break up the function into two parts:

def ask_name():
    pass
def ask_year():
    pass

if that makes more sense for what you are doing.

Does this help? Let me know if you need help with the math.