file - Issue with code not running after user provides input -
i in first year of coding. writing program school having issues with. assignment create trivia game using files. code won't continue after ask user input determine how many points question asked worth. section of code problem posted directly below. entire program below in case needs see whole thing. record entire program not finished yet.
p.s new @ if missed obvious apologize.
while repeat3==true: #identifying point value player wants print "what point value want question 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 1 of values' #asking user question print "here question:" print temporaryquestions[currentcategory][questionvalue]
here entire program far
#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 questions lists #history questions a= open ('history questions.txt','r') reader1=a.readlines() line1 in reader1: historyquestionslist.append(line1) #vinatage tv b= open('vintage tv show questions.txt','r') reader2=b.readlines() line2 in reader2: tvquestionslist.append(line2) #harry potter c=open('harrypotterquestions.txt','r') reader3=c.readlines() line3 in reader3: harrypotterquestionslist.append(line3) #mythology d=open('mythquestions.txt','r') reader4=d.readlines() line4 in reader4: mythquestionslist.append(line4) #prompting print "hello , welcome (for copyright reasons) japordy!" print print "what name?" name=raw_input() print print "you going able chose few types of questions answer" time.sleep(.2) print print "you asked 10 questions" time.sleep(.2) print print "first need decide catagory question then, select question on basis of points." time.sleep(.2) print print "you may chose different catagory each time" time.sleep(.2) print print "after asked question question deleted questions can possibly get" time.sleep(.2) print print "the point system works this, if question right given total number of points question worth." print "but if question wrong fined number of points question worth." print "if take long answer not chance answer , not recieve or fined points" time.sleep(3) print print "the catagories can chose are: history, vintage tv, harry potter, , mythology" time.sleep(.2) print print "the point values 200, 400, 600, 800, , 1000" print #selecting questions asked print "please entre catagory want choose" chosencategory=raw_input() chosencategory=chosencategory.lower()#converting letters lowercase #seeing if user entered valid category , if creating file can used each round. while repeat1==true: while repeat2==true: in range(1,5): if chosencategory==categorys[i-1]: currentcategory=i-1 repeat2=false if repeat2!=false: #selecting questions asked print "the catagories can chose are: history, vintage tv, harry potter, , mythology" print print "please entre catagory want choose" chosencategory=raw_input() chosencategory=chosencategory.lower()#converting letters lowercase while repeat3==true: #identifying point value player wants print "what point value want question 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 1 of values' #asking user question print "here question:" print temporaryquestions[currentcategory][questionvalue] useranswer=raw_input
for python2, input () may not work. use raw_input () if case. secondly, input string comparing integer. (1 0+1 or 2-1 "1" stick , "2" load of pixels swan swimming left. can either compare "200" or compare int(desired_value) 200. also, might want @ switch(),case,default or, since code identical in each case, associative array of min/max values:
randminmax = {200: {1,5}, 400: {5,9} ...} while true: #infinite loop - see 'break' below desired_input = int(raw_input) #might want try/catch in case of bad input if desired_input in randminmax: questionvalue=random.randint(randminmax [desired_input][0], randminmax [desired_input][0]) break; # break out of loop else: print 'please entre 1 of values'
however, there quicker version in case since there fixed relationship between input value , random limits so:
limit = (desired_input / 200) - 1 # 0 4 inclusive if limit==int(limit) , limit < 5: # not, example, 215 limit = (limit * 4) + 1 # 1, 5, 9, 13, 17 questionvalue=random.randint(limit,math.min (limit+4, 20)) # because last limit 20, not 21 - hence math.min break; # got result, stop looping.
a little more asked these principals should along learn code. luck , enjoy!
Comments
Post a Comment