Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to loop this
#1
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)
Reply
#2
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.
Reply
#3
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
(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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
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.
"So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!" - Tim the Enchanter
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020