【发布时间】:2016-08-12 08:36:03
【问题描述】:
我现在是编码的第一年。我正在为我目前遇到一些问题的学校编写程序。任务是使用文件创建一个琐事游戏。在我要求用户输入以确定他们被问的问题的价值后,我的代码将不会继续。有问题的代码部分直接贴在下面。我的整个程序都低于该程序,以防万一任何人需要查看整个程序。只是为了记录整个程序还没有完成。
P.S 我是新手,所以如果我遗漏了一些明显的东西,我深表歉意。
while repeat3==True:
#identifying what point value the player wants
print "what point value do you want the question to have?"
print "your options are:200,400,600,800,1000"
desiredValue=input()
print 'testing'
if desiredValue==200:
questionValue=random.randint(1,5)
repeat3=False
elif desiredValue==400:
repeat3=False
questionValue=random.randint(5,9)
elif desiredValue==600:
repeat3=False
questionValue=random.randint(8,13)
elif desiredValue==800:
repeat3=False
questionValue=random.randint(13,17)
elif desiredValue==1000:
repeat3=False
questionValue=random.randint(17,20)
else:
print 'please entre one of the good values'
#asking the user the question
print "Here is the question:"
print temporaryQuestions[currentCategory][questionValue]
这是我到目前为止的整个程序
#quiz Master Project
#imports
import random
import time
#variables defined
categorys=["history", "vintage tv", "harry potter", 'mythology']
questionFiles=['history questions.txt','vintage tv show
questions.txt','HarryPotterQuestions.txt','mythQuestions.txt']
answerFiles=['history answers.txt','vintageTVAnswers.txt','HarryPotterAnswers.txt','mythAnswers.txt']
chosenCategory=0
HistoryQuestionsList=[]
TVQuestionsList=[]
HarryPotterQuestionsList=[]
MythQuestionsList=[]
temporaryQuestions=[HistoryQuestionsList,TVQuestionsList,HarryPotterQuestionsList,MythQuestionsList]
repeat1=True
repeat2=True
repeat3=True
desiredValue=0
name=0
# functions
#_______________________________________________________________________________
#turning the questions into lists
#history questions
a= open ('history questions.txt','r')
reader1=a.readlines()
for line1 in reader1:
HistoryQuestionsList.append(line1)
#vinatage tv
b= open('vintage tv show questions.txt','r')
reader2=b.readlines()
for line2 in reader2:
TVQuestionsList.append(line2)
#Harry potter
c=open('HarryPotterQuestions.txt','r')
reader3=c.readlines()
for line3 in reader3:
HarryPotterQuestionsList.append(line3)
#Mythology
d=open('mythQuestions.txt','r')
reader4=d.readlines()
for line4 in reader4:
MythQuestionsList.append(line4)
#prompting
print "hello and welcome to (for copyright reasons) japordy!"
print
print "what is your name?"
name=raw_input()
print
print "you are going to be able to chose from a few types of questions to answer"
time.sleep(.2)
print
print "you will be asked 10 questions"
time.sleep(.2)
print
print "first you need to decide what catagory to get a question from then, select a question on the basis of points."
time.sleep(.2)
print
print "you may chose from a different catagory each time"
time.sleep(.2)
print
print "after you are asked a question that question will be deleted from the questions that you can possibly get"
time.sleep(.2)
print
print "the point system works like this, if you get a question right you will be given the total number of points that question was worth."
print "But if you get the question wrong you will be fined the number of points that the question was worth."
print "if you take to long to answer you will not get a chance to answer and you will not recieve or be fined points"
time.sleep(3)
print
print "the catagories that you can chose from are: history, vintage tv, harry potter, and mythology"
time.sleep(.2)
print
print "the point values are 200, 400, 600, 800, and 1000"
print
#selecting the questions that will be asked
print "please entre the catagory you want to choose"
chosenCategory=raw_input()
chosenCategory=chosenCategory.lower()#converting all the letters to lowercase
#seeing if the user entered a valid category and if so creating a file that can be used for each round.
while repeat1==True:
while repeat2==True:
for i in range(1,5):
if chosenCategory==categorys[i-1]:
currentCategory=i-1
repeat2=False
if repeat2!=False:
#selecting the questions that will be asked
print "the catagories that you can chose from are: history, vintage tv, harry potter, and mythology"
print
print "please entre the catagory you want to choose"
chosenCategory=raw_input()
chosenCategory=chosenCategory.lower()#converting all the letters to lowercase
while repeat3==True:
#identifying what point value the player wants
print "what point value do you want the question to have?"
print "your options are:200,400,600,800,1000"
desiredValue=input()
print 'testing'
if desiredValue==200:
questionValue=random.randint(1,5)
repeat3=False
elif desiredValue==400:
repeat3=False
questionValue=random.randint(5,9)
elif desiredValue==600:
repeat3=False
questionValue=random.randint(8,13)
elif desiredValue==800:
repeat3=False
questionValue=random.randint(13,17)
elif desiredValue==1000:
repeat3=False
questionValue=random.randint(17,20)
else:
print 'please entre one of the good values'
#asking the user the question
print "Here is the question:"
print temporaryQuestions[currentCategory][questionValue]
UserAnswer=raw_input
【问题讨论】:
-
这是什么语言?您应该使用该信息标记此问题,因为专家倾向于过滤问题。
标签: file input while-loop