Jump to content

the noob i am!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Timotay

Timotay

    Newbie

  • Members
  • Pip
  • 6 posts
ok this is my code;
a = input ("enter first number")
print a
b = input ("entre secound number")
print "addition", a+b
print "multiply", a*b
print ("close?")
text = raw_input ()
if text == "yes":
exit ()
if text == "no":

now at the end i want to loop back to the start if "no" is entered, but i can't seem to get it.
any advise?
many thanks!
Tim

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
This will help you on the way...
choice = ""
while choice != "no":
    # This is the start
    print "Do you want to try again? Yes/No"
    # If the user writes "yes" then it goes back to "This is the start"
    # Otherwise, it will quit the loop
# and end here.
print "You decided not to try again, and ended the loop"


#3
Timotay

Timotay

    Newbie

  • Members
  • Pip
  • 6 posts
thanks! i came up with this

choice = ""
while choice!= "no":
a = input ("enter first number")
print a
b = input ("enter secound number")
print b
print "addition", a+b
print "multiply", a*b

print ("retry?")
text = raw_input ()

if text == "yes":
exit ()

very nice! lol, just one question the first line what is the function of the two speach marks?? apart from that i get it!
thanks
Tim

#4
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Actually, you can remove that first line, it's not needed. The only thing is does, is to empty the string. I forgot that you don't have to pre-declare Python-variables when I wrote it. So you can simply leave it there or remove it.