Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Can anyone help?

This code runs a incomplete quiz game. I'm trying to count every time some one gets a question wrong or right, and it the end of game. Any thoughts?

spartan_name = ("JOHN")
it_false = ("FALSE")
continue_game = ("CONTINUE")


first_input = input("This is a Halo quiz game. If you type anything in this game make shure it is in all CAPS. Please type CONTINUE to go on with the game.\n")


if first_input == continue_game:
  print("Welcome to the game! first I would like too start of with a true or false question.")

else:
  raise ValueError ("Sorry, that is incorect. Please try again. And remember to have all caps.")



answer = input("\nIs Spartan 117's team named: Feild Team Osiris\nTRUE or FALSE:     ")


if answer == it_false:
  print("CORRECT!!!")

else:
  print("Sorry, that is incorect. 1 wrong.")  #count fix <==========

second_input = input("\nNow to question 2. [push ENTER key]  ")  

answer_two = input("\nWhat is Spartan 117's real name?  ")
if answer_two == spartan_name:
  print("CORRECT!!!")

else:
  print("Sorry, that is incorect. Please try again. And remember to have all caps.")  

2 Answers

Steven Parker
Steven Parker
229,608 Points

It sounds like you just need to keep two running totals. You might start by setting them to 0:

got_right = 0
got_wrong = 0

Then, just increase the one that corresponds with the answer given:

if answer == it_false:
  print("CORRECT!!!")
  got_right += 1   # add to total count
else:
  got_wrong += 1   # add to total count (before print)
  print("Sorry, that is incorrect.", got_wrong, "wrong so far.")

Then you can print out both totals when the game is over.

Thanks man! Completely worked!