0
Program that picks random numbers and user guesses in python
I want to build an app that picks random number automatically from 1 to 10 or 1 to 20 and let the user guess. if guess is right, it awards the user with points. I can write a few lines but the part that makes the app pick random numbers is the problem and also to award point is the problem. this is not a professional job, I just want the code for learning sake. thanks
11 Antworten
+ 9
Here's the random part, I hope you can figure out what's what:
import random
real_value = random.randint(1, 20)
print(real_value)
+ 7
Np. Try it on your own and experiment with it. Later write here if you have any further questions, we'll answer them ;)
+ 7
Take a look what I mean:
https://code.sololearn.com/cXH5UY3fygLp/?ref=app
+ 7
Did you input all inputs needed?
for ex, if the input is in a loop, it needs an input for every time it goes thru the loop
+ 6
If you want a limit of a given number of trials, you can put the input part inside a for loop and break it if the answer is correct.
If you want to ask until guessed, you should use a while loop, instead.
+ 3
@tarrmie That's most likely becuz you didn't input. Eof is end of file (I think), so whatever program it was was looking for an input and it did not get one
+ 1
Your answer was helpful. I want to also add maximum trials before it prints the correct number. I already have this
import random
real_value = random.randint(1, 10)
guess = int(input("pick number\n"))
print(guess)
if (guess ==real_value):
print("You guessed right:\n Congratulation!!!")
else:
print("wrong\ncorrect number is:\n", real_value
0
thanks..
0
can you give a code
0
"got EOF error when reading the line"
0
I did