+ 1

How do I take multiple inputs over a period of time?

Hi, I'm just starting to learn how to code with Python 3.x and I'm trying to make a number game where the user tries to guess a random integer between 1-100. The program is supposed to give a user a hint by telling them if their guess was too high or too low, but I do I let the program give an output and take another guess after that? Here's the code so far: from random import * x = randint(1, 100) # Pick a random number between 1 and 100. print("I'm thinking of a number between 1 and 100.") #informs user guess = input("Guess which number I'm thinking of: ") #takes guess for evaluation print("Your first guess was "+guess) if x > int(guess): print("The number I'm thinking of is higher than "+guess) if x < int(guess): print("The number I'm thinking of is lower than "+guess) if x == int(guess): print("Correct!") print("End") #annouces end of program

6th Jan 2018, 10:30 PM
Jacob Mokszycke
Jacob Mokszycke - avatar
2 Respostas
0
Well as I understand it you simply need to keep the program running *while* the user’s guess is different from the random chosen number. Just put your guess input and hint giving in a “while” loop that will loop until the guess is correct. However, if your intent is to have a limited number of guesses, use a “for” loop.
6th Jan 2018, 11:32 PM
César Sagaert
César Sagaert - avatar
0
use a while loop until user guest correct number. in each iterat, user can input a number.
19th Jan 2018, 10:40 AM
majid gourkani
majid gourkani - avatar