Hello I a beginner trying to practice after completing the codeacademy course. Right now im trying to do a guess a number game.
This is the instructions
The Goal: Similar to the first project, this project also uses the random module in Python. The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. (In other words, the user needs to be able to input information.) If the user’s guess is wrong, the program should return some sort of indication as to how wrong (e.g. The number is too high or too low). If the user guesses correctly, a positive indication should appear. You’ll need functions to check if the user input is an actual number, to see the difference between the inputted number and the randomly generated numbers, and to then compare the numbers.
This is my code
This is the instructions
The Goal: Similar to the first project, this project also uses the random module in Python. The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. (In other words, the user needs to be able to input information.) If the user’s guess is wrong, the program should return some sort of indication as to how wrong (e.g. The number is too high or too low). If the user guesses correctly, a positive indication should appear. You’ll need functions to check if the user input is an actual number, to see the difference between the inputted number and the randomly generated numbers, and to then compare the numbers.
This is my code
from random import randint def guess(x): it = randint(0, 101) if x == it: print("You got it!") elif x > it: print("too high") else: print("too low") print guess(50)The problem with it is I only get one chance to guess. I think i need to use a while statement and some sort of +- symbol, but it kept turning out wrong.