![]() ![]() Then, every time the code loops (they enter an answer), you just increment the counter: num = random.randint(1, 100) This can be done by using a simple counter for how many times the user has made an attempt. You should actually count up and tell the user if they won. ![]() Why are you splitting this on to two different lines? You can just merge the int() onto the line above it, and pass input() into it like this: guess = int(input())Īs Greg Hewgill mentioned in the comments, rather than saying this: print('if you gussed less than 6 times you won') This is not a very extensible design, again, I'd recommend creating a function that allows you to create custom games, like this: def number_guessing_game(low, high, rounds): (This has been implemented below, for reference.) The easiest way to do this would be to use a for. Rather than printing a message saying that if the user got below a certain amount of tries, they win, you can implement it into the code. Print("Guess a number between 1 and 100.") To set up something like this in your code, you'd change your code to something like this. User_integer = input("Enter an integer: ") What you need to do is set up a try- except block, like this: try: ![]() What do you suppose happens if the user enters something like "abc"? Right now, as it stands, you're just converting any user input to a integer, using the int function. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |