Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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