Saturday, 15 September 2012

python - Keep getting ValueError when running while loop -



python - Keep getting ValueError when running while loop -

my code gives me error "valueerror: need more 1 value unpack" when running infinite while loop getting questions untill user types no break out of it. clue 1 more value refering ?

from random import shuffle questions = [ ("which organization develops 802 family of standards wired , wireless lans , mans?", "ieee"), ("what type of delivery uses info link layer addresses?", "local delivery"), ("what organization developed osi reference model used in networking?", "iso"), ("which message delivery alternative used when devices need receive same message simultaneously?", "broadcast"), ("which type of network design combines voice, video, , info on same communication channel?", "converged"), ("during routine inspection, technician discovered software installed on computer secretly collecting info websites visited users of computer. type of threat affecting computer?", "spyware"), ("which device acts gateway allow hosts send traffic remote ip networks?", "local router"), ("what network administrator utilize modify configuration on cisco router?", "ios"), ("to save time, ios commands may partially entered , completed typing key or key combination?", "tab"), ("an administrator measured transfer of usable info across 100 mb/s physical channel on given period of time , obtained 60 mb/s. kind of measurement did administrator obtain?", "goodput"), ] shuffle (questions) numright = 0 numquest = 0 wrong = [] print ("welcome computer networking quiz, based on cisco material.") while true: questions, rightanswer in questions: reply = input(questions + " ") if answer.lower() == rightanswer: print("congratulations, right answer!") numright += 1 numquest += 1 answer2 = input("would continue? type yes or no: ") if answer2.lower() == "no": break else: print("that wrong reply friend!") numquest += 1 answer2 = input("would continue? type yes or no: ") if answer2.lower() == "no": break = numright b = numquest def stats(a,b): homecoming a/b*100 if stats(a,b) >= 60.0: print("you got", stats(a,b), "percent right. pass!") else: print("you got", stats(a,b), "percent right. fail!")

your problem simple: "break" phone call within loop "breaking" loop on for, not on while. in order solve it, need maintain variable "break_while", initialized false , utilize status while. when user answers "no" set variable true , while stop:

while (not break_while): *** if answer2.lower() == "no": break_while = true break

edit: taking closer @ code, must carefull usage of 2 different variables same name, namely "questions"

for questions, rightanswer in questions: ***

you getting error because after usage of break, while still active , sentence beingness called again, value of variable "questions" changed particular question, not tuple , valueerror beingness raised. alter name of first "questions" "question" in order avoid such conflict.

python python-3.x

No comments:

Post a Comment