Rebooting program after input() automatically on python

James H.

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

Padraic Cunningham
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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Timezone changing automatically to 'Chicago' after rebooting CentOS 7

From Dev

after compiling python program, how to input arguments

From Dev

Tkinter window closes automatically after Python program has run in PyCharm

From Dev

Tkinter window closes automatically after Python program has run in PyCharm

From Dev

Python: wait for user input, and if no input after 10 minutes, continue with program

From Dev

Program is hanging after input

From Dev

Program blocks after input

From Dev

Program is hanging after input

From Dev

Python Input 0 automatically

From Dev

Input and Output program for python

From Dev

Python program not asking for input

From Dev

program automatically closing after writing to socket

From Dev

program automatically closing after writing to socket

From Dev

How to automatically restart a program after it's closed

From Dev

Custom keymapping is lost after rebooting

From Dev

Set alarms after rebooting Phone

From Dev

broadcastreceiver does not kick in after rebooting

From Dev

Ending a python program with user input

From Dev

Processing user input in a python program

From Dev

How To Make a Python Program Automatically Restart Itself

From Dev

Java documentlistener - program stop working after input

From Dev

C Program crashes after last input

From Dev

Start a program after waiting for user input

From Dev

Program closes right after the last input

From Dev

Program ends after user input is invalid

From Dev

Not rebooting to the lastest kernel after update to grub 2

From Dev

Desktop computer rebooting after ~3 hours

From Dev

Unable to resume KVM guest after rebooting host

From Dev

Cannot login after running startx and rebooting

Related Related

HotTag

Archive