Python Forum

Full Version: how to loop this
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
guess = input("guess a number between 1 and 50 ")
guess = int(guess)
if guess == 31:
print("yes!The correct answer is " + str(guess) )
else:
print("wrong,try again ")





this is my code,but I dont know how to loop it,can someone please give suggestions on how to fix it(im a 12 year old kid that just started,so I need some help)
What kinds of loop have you learnt about? If none, how are you learning the language? You should learn about loops in whatever materials you're using.
Python has built-in help, so you can just type help('while') and help('for') in interactive interpreter (press Q to exit from help) to learn about loops.
(Aug-18-2020, 03:24 AM)dirtdude Wrote: [ -> ]guess = input("guess a number between 1 and 50 ")
guess = int(guess)
if guess == 31:
print("yes!The correct answer is " + str(guess) )
else:
print("wrong,try again ")





this is my code,but I dont know how to loop it,can someone please give suggestions on how to fix it(im a 12 year old kid that just started,so I need some help)
If you are aware of for loops and while loops, I'm pretty sure youu would be knowing the answer. However, to help youu to begin with, a while loop is basically a loop that runs until a given condition is satisfied, whereas a for loop is used for iterating over a sequence
In addition to the built-in help Python also has a nice, quick tutorial in its documentation written by Guido van Rossum (inventor of Python). It only takes a couple hours to read through it and you will have all the basics covered.

In Windows: Start > Python 3 > Python 3 Manuals. then read the section called The Python Tutorial.