0

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.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
user2322274
  • 25
  • 1
  • 8
  • Oh, do you mean that it is constantly asking you to enter data? and you don't want it to? – bozdoz Apr 26 '13 at 04:15
  • there is no problem with program, it is working(this is not a full code of program). I want command line to "refresh"(dunno if it's write term"). When i start program it says: Enter Data, i enter it, it gives me information. then it repeats "Enter Data", but under information it gave to me. i want it to delete everything and ask on the blank page to "Enter Data" – user2322274 Apr 26 '13 at 04:21

2 Answers2

1

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()
Community
  • 1
  • 1
gatto
  • 2,947
  • 1
  • 21
  • 24
0

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.

bozdoz
  • 12,550
  • 7
  • 67
  • 96