1

I have a question about python 3.4.1

So suppose you have a program like this:

name = input("What is your name?")
print("Hi", name ,'!')

So you get:

.>>> What is your name?

So you type in you James and you get back:

.>>> Hi James!

Then after it prints this little message, it automatically resets, and goes back to:

.>>> What is you name?

Thanks for you time! :D

1 Answer 1

2
while True:
    name = input("What is your name?")
    print("Hi", name ,'!')

Use a while loop

You need some condition to break out of the loop:

while True:
    name = input("Enter your name or press q to quit")
    if name == "q": 
        break    # if user enters `q`, we will end the loop with this break statement
    print("Hi", name ,'!') # or else just print the name

A nice tutorial on while loops.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you once again Padraic!
@JamesH., have a look at learnpythonthehardway, it will get you going on all the basics and you will have fun too ;) learnpythonthehardway.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.