pubnsa.blogg.se

Java random pick a number between 1 and 3
Java random pick a number between 1 and 3







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.

java random pick a number between 1 and 3

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.









Java random pick a number between 1 and 3