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

What loop should I use to efficiently ask for the input again if a Value error occurs?

I would like to find out how i can loop the code n the video to ask for input again if a Value error happens, without needing to type the entire code again.

1 Answer

Robert Lyon
Robert Lyon
7,551 Points

You could use a while loop to ask for input again. Here is a simple example of asking for input again, hope it helps.

word = input("what is the greeting?") 

while word != "hello":
    word = input("what is the greeting?")

Hi Robert i thought it would show what video i asked the question on but it didn't, i was wondering how i could do this loop using test and except and using Value error in excpet