【发布时间】:2014-04-13 11:10:50
【问题描述】:
我正在开发一个简单的程序,该程序将文本文件作为列表读取,然后以网格样式显示该列表。然后我想在屏幕上显示列表,我已经成功地做到了,但我在每个单词的末尾不断得到 /r/n。你如何删除/r/n?此外,如果我想在下一行 a、b 和 d 出现之前清除行 a、b 和 c,我将如何清除屏幕(它是 OS 系统 CLS)还是只打印 50 个空白行的循环?
到目前为止,这是我的程序(不完整),我知道可能有更好的方法,但对我来说这是一个开始,有没有更好的方法人们会建议改进(很好,我正在寻求改进建议) .
import time
print ('welcome to the missing word guessing game: ')
print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
menu = ('Menu \n 1. Easy game - press e \n 2. Hard game - press h \n 3. Quit - press q')
print (menu)
user_input = raw_input('Please type your response: ')
if user_input == 'e':
file =open('words.txt', 'r')
word_list = file.readlines()
row_a = word_list [0:3]
row_b = word_list [3:6]
row_c = word_list [6:9]
row_d = word_list [7:10]
print (row_a)
print (row_b)
print (row_c)
print ('study the words')
time.sleep (5)
print ('Please wait - Do not touch any thing - just study')
time.sleep (5)
print ('Now study the words again, can you spot the word that is missing? ')
print (row_a)
print (row_b)
print (row_d)
user_answer = raw_input('Can you guess the word that is missing? ')
if user_answer == 'brown':
print ('Well done')
print (menu)
else:
print ('Wrong answer')
【问题讨论】: