Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Caleb Newell
Caleb Newell
12,562 Points

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
220,378 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.

Caleb Newell
Caleb Newell
12,562 Points

Thanks man! Completely worked!