while loop - where have i went wrong with my code? -


attempt = 0 answer = "canberra": while answer != "canberra"         input("what capital of australia: ?")  print(attempt) 

i don't know whats wrong it. basically, task write code repeatedly ask user question until answer correct. however, when run code, repeatedly asks question when answer question correctly. able "if" statements task requires use "while" loops please, if can, help!!(don't on complicate though.) :)

loops

  1. it's unclear programming language use. think it's python :)
  2. you should increment attempts counter in while loop this: attempt += 1
  3. in beginnig of while loop comparing variable answer string 'canberra'. comparsion returns false because variable answer have 'canberra' inside. "canberra" != "canberra" => false.
  4. you have colon @ end of line answer = "canberra":, should @ end of next line while answert ....

the code:

attempt = 0 answer = "" correct_answer = "canberra"  while answer != correct_answer:     answer = input("what capital of australia? ")     attempt += 1 print(attempt) 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -