我在編碼的第一年。我正在編寫一個我目前遇到問題的學校計劃。該任務是使用文件創建一個瑣事遊戲。在我詢問用戶輸入以確定他們被問到的問題值多少分之後,我的代碼將不會繼續。具有問題的代碼部分直接在下面發佈。我的整個計劃都低於這個水平,以幫助任何人需要看到整個事情。只是爲了記錄整個程序尚未完成。用戶提供輸入後代碼未運行問題
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
這是什麼語言?你應該用這個信息來標記這個問題,因爲專家傾向於過濾問題。 –