Monday, 15 July 2013

python - Equals not being equals -



python - Equals not being equals -

can't python quiz programme work, when 'useranswer' 'correctanswer' if loop doesn't work , states aren't equal when are. i'm wondering if problem comparing strings saved in lists, stuck prepare it. help much appreciated.

thank you

import sys print ("game started") questions = ["what rad stand for?", "why rad faster other development methods?", "name 1 of 3 requirements user friendly system", "what efficient design?", "what definition of validation method?"] answers = ["a - random applications development, b - available diskspace, c - rapid applications development", "a - prototyping faster creating finished product, b - through utilize of case tools, c - end user evaluates before dev team", "a - efficient design, b - intonated design, c - aesthetic design", "a - 1 makes best utilize of available facilities, b - 1 allows user input info accurately, c - 1 end user comfortable with", "a - rejection of info occurs because input breaks predetermined criteria, b - double entry of info ensure accurate, c - adaption cope alter external system"] correctanswers = ["c", "b", "a", "a", "a"] score = 0 lives = 4 z = 0 in range(len(questions)): if lives > 0: print (questions[z]) print (answers[z]) useranswer = (input("please come in right answer's letter here: ")) correctanswer = correctanswers[z] if (useranswer) (correctanswer): //line im guessing problem occurs on print("correct, done!") score = score + 1 else: print("incorrect, sorry. right reply was; " + correctanswer) lives = lives - 1 print("you have, " + str(lives) + " lives remaining") z = z + 1 else: print("end of game, no lives remaining") sys.exit() print("well done, scored" + int(score) + "//" + int(len(questions)))

you should utilize == comparison:

if useranswer == correctanswer:

is operator identity comparison. , ==, >, operators value comparison, , need.

for 2 objects, obj1 , obj2:

obj1 obj2 iff id(obj1) == id(obj2) # iff means `if , if`.

python equals

No comments:

Post a Comment