Skip to content
Advertisement

python quiz validation not working

The validation doesnt work. im not sure why, is there a way to validate a string. The questions asked are endless i need 10 questions to be asked

JavaScript

The validation doesnt work. im not sure why, is there a way to validate a string

Advertisement

Answer

In the third line, you ask for input. But a name is a string, so you need raw_input. raw_input takes strings, input only takes numerical values. Python 2.7 getting user input and manipulating as string without quotations

Nowhere in your code do you update the variable questions, which I am guessing is a counter. You have to update that whenever a question is asked, using question += 1.

Finally, your code at the end does not really make sense. Based off the code, it checks for whether or not it is a string, but then compares it to the answer regardless. The if statement needs to be within the try.

The else statement does not match any outer indentation.

Finally, because of the while True: your code will never exit the loop unless the answer is wrong. At the point the entire program terminates. I see what kind of program you are trying to write, but the parameters for random number generation have to be within some kind of a while question <= 10 loop. As of now, only two lines in the program are being affected by that first while loop.

EDIT: I am working on a good example code. Hopefully this answer will help until I can finish it. EDIT: Here is code that shows how it works within a while loop.

JavaScript

Happy coding! and best of luck!

Advertisement