guessing script - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: guessing script (/thread-396.html) |
guessing script - simon - Oct-09-2016 Hello, this is my first time in python and i need help with my code, i want to guess a number between 1-100, but the problem is i can only guess 1-3times , i want to guess until i get the correct answer, can you help me? import random gissat = 0 rätt = random.randint(1, 100) print("Gissa talet:") while gissat<rätt: gissat = input() gissat = int(gissat) if gissat<rätt: print ("För litet!") if gissat>rätt: print ("För stort!") if gissat==rätt: break RE: guessing script - Mekire - Oct-09-2016 You break out of the code when correct so you want to loop continously. Change this while gissat<rätt:To this: while True: RE: guessing script - snippsat - Oct-09-2016 Try to write in English in code. It's okay to use Swedish in output part that user see. Using !=(Not equal) and it will natural break out of the loop, when right number is guessed. Eg. import random print("Gussing Game") secret_number = random.randint(1, 100) gissat = 0 while gissat != secret_number: gissat = int(input('Gissa talet: ')) if gissat < secret_number: print("För litet!") if gissat > secret_number: print("För stort!") print('You gussed it the number was {}'.format(secret_number)) RE: guessing script - simon - Oct-10-2016 thank you so much, this solved my problem, and im sorry for writing in swedish, didnt think about it lol, next time i will translate before :D |