Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I have a "press enter to continue" feature in python? [duplicate]

Tags:

python

I am writing a choose-your-own-adventure style game in python (terminal based) and I would like the program to pause printing until the enter button is pressed. Here is an example.

print("zzzzzzzzz")

the press enter to continue would come here. Then, after they press enter, this block would run.

print("yyyyyy")

Python 3 is preferable.

like image 336
Pranav A. Avatar asked Feb 06 '17 21:02

Pranav A.


People also ask

How do I add a press Enter to continue in Python?

In Python 3 use input(): input("Press Enter to continue...") In Python 2 use raw_input(): raw_input("Press Enter to continue...")

How do you run a line again in Python?

You could use a simple while loop: line = "Y" while line[0] not in ("n", "N"): """ game here """ line = input("Play again (Y/N)?")

How do you continue or exit the program by pressing the keys?

1: press "Enter" to continue. 2: press "Esc" to exit the program.

How do you delay 1 second in Python?

If you've got a Python program and you want to make it wait, you can use a simple function like this one: time. sleep(x) where x is the number of seconds that you want your program to wait.


1 Answers

Python 2:

raw_input("Press Enter to continue...")

Python 3:

input("Press Enter to continue...")
like image 149
Z.D. Avatar answered Oct 26 '22 23:10

Z.D.