Reputation: 25
I started learning python few days ago, I wrote an easy program. A user enters data and it gives information about the data.
while True:
x = input("Enter Data: ")
if x == z:
print("")
if x == y:
print("")
if x == l:
print("")
if x == k:
print("")
I am using program in windows command line. What I am trying to do is: when you "enter data" and program gives you information, you press enter and command line refresh and "enter data" appears again.
Upvotes: 0
Views: 3652
Reputation: 2957
On Windows you can use cls
to clear screen (see this question for details):
import os
import sys
while True:
value = raw_input('Enter data: ')
if value == 'quit':
break
print value
# wait for enter key
sys.stdin.read(1)
os.system('cls')
Curses example:
import curses
w = curses.initscr()
while True:
w.addstr("Enter data: ")
value = w.getstr()
if value == 'quit':
break
w.addstr('data: %s\n' % value)
w.addstr('Press any key to continue')
w.getch()
w.clear()
w.refresh()
curses.endwin()
Upvotes: 1
Reputation: 12870
while True:
means "keep doing this". So it's going to keep asking you to enter data. Maybe what you're looking for is to define a function instead: def ask():
instead, and then in the command line, type ask()
, and it will prompt you only the one time, which is what I am guessing you want.
Upvotes: 0