Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I have a problem, I tried to put all possible numbers but noone is the correct. Why? Thank you so much.

Python
import random
casual=random.randint(1,10)
user=0
while user != casual:
    user=input("type: ")
    if user == casual:
        print("correct")
    else:
        print("wrong")


What I have tried:

Also if I print the random number first and then input that, it is wrong. I can't understand.
Posted
Updated 14-Jan-17 21:11pm
Comments
Patrice T 14-Jan-17 19:20pm    
"it is wrong" is not informative, please explain who it is wrong.

On first look I see nothing obvious, but I am not Python specialist.

Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
A simple bit of debugging would show you what is happening: printing the values of each variable shows that user contains a string value. So you need to use the int() function to convert it to a number.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900