Python code error

moshingbonzo

Commendable
Sep 13, 2016
8
0
1,510
I am really struggling to find the error with the python code i have created for my a-level computer science class. Any help would be appreciated. (Using version 3.5)

import time

print("Quiz time!")
print()
time.sleep(1)
print("Question 1")
time.sleep(1)
q1=input("What is the capital city of France?:")
if q1 == "Paris" :
"answer1"==1
print("Correct! :)")
elif q1 == "paris" :
"answer1"==1
print("Correct! :)")
else:
"answer1"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 2")
time.sleep(1)
q2=input("Jeremy Clarkson and his team were recently fired but where will their new show be streamed:")
if q2 == "Amazon":
"answer2"==1
print("Correct! :)")
elif q2 == "amazon":
"answer2"==1
print("Correct! :)")
elif q2 == "Amazon Prime":
"answer2"==1
print("Correct! :)")
elif q2 == "Amazon prime":
"answer2"==1
print("Correct! :)")
elif q2 == "amazon prime":
"answer2"==1
print("Correct! :)")
else:
"answer2"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 3")
time.sleep(1)
q3=input("What is the longest river in the world?:")
if q3 == "Nile":
"answer3"==1
print("Correct! :)")
elif q3 == "nile":
"answer3"==1
print("Correct! :)")
elif q3 == "The River Nile":
"answer3"==1
print("Correct! :)")
elif q3 == "the river nile":
"answer3"==1
print("Correct! :)")
elif q3 == "The river nile":
"answer3"==1
print("Correct! :)")
elif q3 == "the River Nile":
"answer3"==1
print("Correct! :)")
elif q3 == "River Nile":
"answer3"==1
print("Correct! :)")
elif q3 == "River nile":
"answer3"==1
print("Correct! :)")
elif q3 == "river nile":
"answer3"==1
print("Correct! :)")
else:
"answer3"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 4")
time.sleep(1)
q4=input("What job does Homer Simpson do at the Springfield Nuclear Power Plant?:")
if q4 == "Safety Inspector":
"answer4"==1
print("Correct! :)")
elif q4 == "safety inspector":
"answer4"==1
print("Correct! :)")
elif q4 == "Safety inspector":
"answer4"==1
print("Correct! :)")
elif q4 == "saftey inspector":
"answer4"==1
print("Correct! :)")
else:
"answer4"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 5")
time.sleep(1)
q5=input("What building is located on Pennsylvania Avenue:")
if q5 == "White House":
"answer5"==1
print("Correct! :)")
elif q5 == "white house":
"answer5"==1
print("Correct! :)")
elif q5 == "White house":
"answer5"==1
print("Correct! :)")
elif q5 == "The White House":
"answer5"==1
print("Correct! :)")
elif q5 == "The white house":
"answer5"==1
print("Correct! :)")
elif q5 == "the white house":
"answer5"==1
print("Correct! :)")
else:
"answer5"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 6")
time.sleep(1)
q6=input("The invasion of which country by Nazi Germany sparked WW2:")
if q6 == "Poland":
"answer6"==1
print("Correct! :)")
elif q6 == "poland":
"answer6"==1
print("Correct! :)")
else:
"answer6"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 7")
time.sleep(1)
q7=input("Which adult orientated cartoon is based around a burger resturaunt?:")
if q7 == "Bobs Burgers":
"answer7"==1
print("Correct! :)")
elif q7 == "Bobs burgers":
"answer7"==1
print("Correct! :)")
elif q7 == "bobs burgers":
"answer7"==1
print("Correct! :)")
elif q7 == "Bob's Burgers":
"answer7"==1
print("Correct! :)")
elif q7 == "Bob's burgers":
"answer7"==1
print("Correct! :)")
elif q7 == "bob's burgers":
"answer7"==1
print("Correct! :)")
else:
"answer7"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 8")
time.sleep(1)
q8=input("How old is the queen:")
if q8 == "90":
"answer8"==1
print("Correct! :)")
else:
"answer8"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 9")
time.sleep(1)
q9=input("In which year was netflix founded?:")
if q9 == "1997":
"answer9"==1
print("Correct! :)")
elif q9 == "97":
"answer9"==1
print("Correct! :)")
else:
"answer9"==0
print("Incorrect :(")
print()
time.sleep(1)
print("Question 10")
time.sleep(1)
q10=input("What was the Snickers chocolate bar origionally called?:")
if q10 == "marathon":
"answer0"==1
print("Correct! :)")
elif q10 == "Marathon":
"answer0"==1
print("Correct! :)")
elif q10 == "marathon bar":
"answer0"==1
print("Correct! :)")
elif q10 == "Marathon bar":
"answer0"==1
print("Correct! :)")
elif q10 == "Marathon Bar":
"answer0"==1
print("Correct! :)")
else:
"answer0"==0
print("Incorrect :(")
print()
time.sleep(1)
sum=int("answer1"+"answer2"+"answer3"+"answer4"+"answer5"+"answer6"+"answer7"+"answer8"+"answer9"+"answer0")
print("You scored",sum)
if "answer1" == 0:
print("The capital of France is Paris")
if "answer2" == 0:
print("The Grand tour staring the trio streams on Amazon Prime in November")
if "answer3" == 0:
print("The Nile is the worlds largest river")
if "answer4" == 0:
print("Homer works as a Safety Inspector")
if "answer5" == 0:
print("The White House is located on Pennsylvania Avenue")
if "answer6" == 0:
print("The Nazi and Soviet invasion of Poland started WW2")
if "answer7" == 0:
print("Bobs Burgers is based in the resturaunt Bobs Burgers")
if "answer8" == 0:
print("The queen recently turned 90 and had a televised celebration hosted by Ant & Dec")
if "answer9" == 0:
print("Netflix was founded in august of 1997")
if "answer0" == 0:
print("Before being renamed Snickers the nutty bar was originally called a Marathon Bar")
time.sleep(1)
print()
time.sleep(1)
print("Thank you for playing")
 

ex_bubblehead

Distinguished
Moderator
Rather than just throwing up a wall of code and expecting us do the work for you, how about telling everyone what errors are generated and what you have done so far to troubleshoot?

We're not here to do your homework for you. We will help guide, but we won't do the work for you.
 

moshingbonzo

Commendable
Sep 13, 2016
8
0
1,510


Sorry if I wasn't clear it is for my computer science class but not homework. I did this of my own accord to help learn python quicker.
As for the error I have had several and each time I think I have figured it out I am proven wrong and honestly have no idea where the error is
I have tried changing all sorts of the code but have only been using python for two weeks and don't know it well enough to understand it properly. After spending all evening working on it I decided I should ask someone with more knowledge for help. The forum also wouldn't let me add an attachment and not knowing what the error was I had to copy and paste it into the question.
I think that the error occurs at the int addition towards the end as all the questions appear to work correctly however am not sure what causes it to not work
Very sorry if it sounded like I was asking you to do my homework for me I am just trying to get my head around python as many of my class already have a good understanding and I need to try and catch up in my spare time
 

moshingbonzo

Commendable
Sep 13, 2016
8
0
1,510


I do not get a syntax error i get this

Traceback (most recent call last):
File "E:\18 Quiz.py", line 212, in <module>
sum=int("answer1"+"answer2"+"answer3"+"answer4"+"answer5"+"answer6"+"answer7"+"answer8"+"answer9"+"answer0")
ValueError: invalid literal for int() with base 10: 'answer1answer2answer3answer4answer5answer6answer7answer8answer9answer0

Not really sure what it means but guessing i need to change the calculation. The only problem is everything i do to it just seems to result in more errors and not having a value for each individual answer,
Also thanks for the site it looks very useful. At the moment I am using a power point designed by a high school teacher and its not very useful so this may help.
 

moshingbonzo

Commendable
Sep 13, 2016
8
0
1,510
MERGED QUESTION
Question from moshingbonzo : "python 3.5 code issues"

I have been learning python code on my own to gain an advantage in my computer science class for the last couple of weeks from a collection of lessons put online by a high school teacher. Since then i have learnt quite a lot and created several small programs however have just tried to create a 10 question quiz.
The program works right up to a calculation and despite having done them before and looking through the power points i have been working through.

This is the code for the questions and the error and if anyone could help me out that would be great. Ill also post the rest of the code below just in case but i don't believe there are any issues with it.

The code
print("Incorrect :( ")
print()
time.sleep(1)
sum=int("answer1"+"answer2"+"answer3"+"answer4"+"answer5"+"answer6"+"answer7"+"answer8"+"answer9"+"answer0")
print("You scored",sum)

The Error
Traceback (most recent call last):
File "E:\18 Quiz.py", line 212, in <module>
sum=int("answer1"+"answer2"+"answer3"+"answer4"+"answer5"+"answer6"+"answer7"+"answer8"+"answer9"+"answer0")
ValueError: invalid literal for int() with base 10: 'answer1answer2answer3answer4answer5answer6answer7answer8answer9answer0

The rest of the code:


import time

print("Quiz time!")
print()
time.sleep(1)
print("Question 1")
time.sleep(1)
q1=input("What is the capital city of France?:")
if q1 == "Paris" :
"answer1"==1
print("Correct! :) ")
elif q1 == "paris" :
"answer1"==1
print("Correct! :) ")
else:
"answer1"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 2")
time.sleep(1)
q2=input("Jeremy Clarkson and his team were recently fired but where will their new show be streamed:")
if q2 == "Amazon":
"answer2"==1
print("Correct! :) ")
elif q2 == "amazon":
"answer2"==1
print("Correct! :) ")
elif q2 == "Amazon Prime":
"answer2"==1
print("Correct! :) ")
elif q2 == "Amazon prime":
"answer2"==1
print("Correct! :) ")
elif q2 == "amazon prime":
"answer2"==1
print("Correct! :) ")
else:
"answer2"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 3")
time.sleep(1)
q3=input("What is the longest river in the world?:")
if q3 == "Nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "The River Nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "the river nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "The river nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "the River Nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "River Nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "River nile":
"answer3"==1
print("Correct! :) ")
elif q3 == "river nile":
"answer3"==1
print("Correct! :) ")
else:
"answer3"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 4")
time.sleep(1)
q4=input("What job does Homer Simpson do at the Springfield Nuclear Power Plant?:")
if q4 == "Safety Inspector":
"answer4"==1
print("Correct! :) ")
elif q4 == "safety inspector":
"answer4"==1
print("Correct! :) ")
elif q4 == "Safety inspector":
"answer4"==1
print("Correct! :) ")
elif q4 == "saftey inspector":
"answer4"==1
print("Correct! :) ")
else:
"answer4"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 5")
time.sleep(1)
q5=input("What building is located on Pennsylvania Avenue:")
if q5 == "White House":
"answer5"==1
print("Correct! :) ")
elif q5 == "white house":
"answer5"==1
print("Correct! :) ")
elif q5 == "White house":
"answer5"==1
print("Correct! :) ")
elif q5 == "The White House":
"answer5"==1
print("Correct! :) ")
elif q5 == "The white house":
"answer5"==1
print("Correct! :) ")
elif q5 == "the white house":
"answer5"==1
print("Correct! :) ")
else:
"answer5"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 6")
time.sleep(1)
q6=input("The invasion of which country by Nazi Germany sparked WW2:")
if q6 == "Poland":
"answer6"==1
print("Correct! :) ")
elif q6 == "poland":
"answer6"==1
print("Correct! :) ")
else:
"answer6"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 7")
time.sleep(1)
q7=input("Which adult orientated cartoon is based around a burger resturaunt?:")
if q7 == "Bobs Burgers":
"answer7"==1
print("Correct! :) ")
elif q7 == "Bobs burgers":
"answer7"==1
print("Correct! :) ")
elif q7 == "bobs burgers":
"answer7"==1
print("Correct! :) ")
elif q7 == "Bob's Burgers":
"answer7"==1
print("Correct! :) ")
elif q7 == "Bob's burgers":
"answer7"==1
print("Correct! :) ")
elif q7 == "bob's burgers":
"answer7"==1
print("Correct! :) ")
else:
"answer7"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 8")
time.sleep(1)
q8=input("How old is the queen:")
if q8 == "90":
"answer8"==1
print("Correct! :) ")
else:
"answer8"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 9")
time.sleep(1)
q9=input("In which year was netflix founded?:")
if q9 == "1997":
"answer9"==1
print("Correct! :) ")
elif q9 == "97":
"answer9"==1
print("Correct! :) ")
else:
"answer9"==0
print("Incorrect :( ")
print()
time.sleep(1)
print("Question 10")
time.sleep(1)
q10=input("What was the Snickers chocolate bar origionally called?:")
if q10 == "marathon":
"answer0"==1
print("Correct! :) ")
elif q10 == "Marathon":
"answer0"==1
print("Correct! :) ")
elif q10 == "marathon bar":
"answer0"==1
print("Correct! :) ")
elif q10 == "Marathon bar":
"answer0"==1
print("Correct! :) ")
elif q10 == "Marathon Bar":
"answer0"==1
print("Correct! :) ")
else:
"answer0"==0
print("Incorrect :( ")
print()
time.sleep(1)
sum=int("answer1"+"answer2"+"answer3"+"answer4"+"answer5"+"answer6"+"answer7"+"answer8"+"answer9"+"answer0")
print("You scored",sum)
if "answer1" == 0:
print("The capital of France is Paris")
if "answer2" == 0:
print("The Grand tour staring the trio streams on Amazon Prime in November")
if "answer3" == 0:
print("The Nile is the worlds largest river")
if "answer4" == 0:
print("Homer works as a Safety Inspector")
if "answer5" == 0:
print("The White House is located on Pennsylvania Avenue")
if "answer6" == 0:
print("The Nazi and Soviet invasion of Poland started WW2")
if "answer7" == 0:
print("Bobs Burgers is based in the resturaunt Bobs Burgers")
if "answer8" == 0:
print("The queen recently turned 90 and had a televised celebration hosted by Ant & Dec")
if "answer9" == 0:
print("Netflix was founded in august of 1997")
if "answer0" == 0:
print("Before being renamed Snickers the nutty bar was originally called a Marathon Bar")
time.sleep(1)
print()
time.sleep(1)
print("Thank you for playing")


 

moshingbonzo

Commendable
Sep 13, 2016
8
0
1,510


That is help full and it does appear that the string is wrong for the answers for the questions (and used in the sum) but whenever i remove the "'s from either side the program fails to start completely
 

moshingbonzo

Commendable
Sep 13, 2016
8
0
1,510
figured it out. The issue wasn't with the questions but with the final calculation.It the use of brackets around the answers and the use of double brackets for these calculations. Once i changed them around it was all sorted and works now. Thanks for the help rgd1101 :)