0

What If?

what if i have created a number guessing game and i want the user to keep on guessing the number until he/she gets the correct answer. But in this app i dont know how to deal with those inputs. My program print "please type higher number" or "please type low number than uh just input" but in this app it wont work coz this r gonna show at last, after the input is done. So can uh suggest me something?

25th Jul 2022, 2:18 PM
Sudip Shrestha
Sudip Shrestha - avatar
6 Answers
+ 3
Sudip Shrestha Please share your code.
25th Jul 2022, 2:53 PM
RšŸšŸ‡®šŸ‡³
RšŸšŸ‡®šŸ‡³ - avatar
+ 2
I think this is related to your previous question and code: https://www.sololearn.com/Discuss/3065043/?ref=app
25th Jul 2022, 3:18 PM
Lisa
Lisa - avatar
+ 2
Please put your code in a script on sololearn playground ā€“ that way it is much more readable.
25th Jul 2022, 3:32 PM
Lisa
Lisa - avatar
+ 1
I can't see your learning progress when I went to visit your profile. But if you join the Python Core tutorial, you'll find a chapter covering exception handling topic "Exceptions and Files". I think you can employ the techniques covered in it to cope with this, at least to evade the program from crashing when there isn't enough input provided in the input dialog (when running the code). However, as what had been told, we can't expect a full interactive I/O here, like seeing the input prompts etc. This is just the general way online code processors do the work.
25th Jul 2022, 2:53 PM
Ipang
0
import random computer_guess = random.randint(1, 500) print('Hello World! In this game you have to guess the number which computer has picked. So lets begin, Good Luck!!') trials = 1 player_pick = 0 def start(): print("Congrats. " + str(player_pick) + " is the correct answer.") print('uh guessed it in ' + str(trials) + ' trials') print("thanks uh for using this program.") while player_pick != computer_guess: player_pick = input('Please choose a number between 1 to 500. I choose:') player_pick = int(player_pick) if 1 > player_pick > 500: print(player_pick, 'is not included in the number between 1 to 500. So, please try again with valid number.') continue elif player_pick > computer_guess: print(player_pick, 'is too high. please try again with low number.') trials += 1 continue elif player_pick < computer_guess: print(player_pick, ' is too low. please try again with high number.') trials += 1 continue elif player_pick == computer_guess: start() (here is my code)
25th Jul 2022, 3:26 PM
Sudip Shrestha
Sudip Shrestha - avatar
0
Can uh plz check my profile. I just posted it.
26th Jul 2022, 1:46 AM
Sudip Shrestha
Sudip Shrestha - avatar