Oct-15-2020, 10:49 AM
Hi, im a beginner to python and i was trying to test my knowledge by creating a simple game, it's a quiz game of four questions, each question answered correctly gets you five points and logs them into a file called "lista risultati.txt" and when you complete the game your final score is registered on "risultato finale.txt", at the start of the game it asks you if you want to play you need to answer "yes" or "no" if you say no it will exit if you say yes you will play and if you say something else there will be an error and the program will bring you back to the question, i cant manage to find the error in my code that makes the compiler say "invalid syntax", im sorry for bad grammar/spelling english is not my first language, i will report the code of my game and the error below:
Ps. im using python 3.6
CODE:
Ps. im using python 3.6
CODE:
import sys print("**********************") print("*welcome to QuizWorld*") print("**********************") print(" v.1.0.0 ") print("rules: Do not cheat each answer will give you 5 points, if you get more then 15 points you win if you get less you loose, after you win or lose go check out your answers and final points on lista risultati or punteggio finale") def yes(): a = input("do you want to play? ") if a == "yes": del a print("ok, so first question") print("whats the capital of italy?") a = input("answer: ") if a == "rome": print("correct") a1 = 5 with open("lista risultati.txt", 'w') as f f.write(str(a1\n)) else: a1 = 0 print("wrong") with open("lista risultati.txt", 'w') as f f.write(str(a1\n)) f.close print("second question") print("1*2*3*4*5*6*7*8*9*0*1*1*0*1") b = input("answer: ") if b == 0: print("correct") b1 = 5 with open("lista risultati.txt", 'w') as f f.write(str(b1\n) else: b1 = 0 print("wrong") with open("lista risultati.txt", 'w') as f f.write(str(b1\n) f.close print("third question") print("does it weight more 1 pound of steel or 1 pound of feathers") c = input("answer: ") if c == "they weight the same": print("correct") c1 = 5 with open("lista risultati.txt", 'w') as f f.write(str(c1\n)) else: c1 = 0 print("wrong") with open("lista risultati.txt", 'w') as f) f.write(str(c1\n) f.close print("FINAL question") print("is this program good?") d = input("answer: ") if d == "yes": print("correct") d1 = 5 with open("lista risultati.txt", 'w') as f f.write(str(d1)) else: d1 = 0 print("wrong") with open("lista risultati.txt", 'w') as f f.write(str(d1)) f.close e = a1 + b1 + c1 + d1 with open("risultato finale.txt", 'w') as f1 f1.write(str(e) f1.close r = open("risultato finale.txt", "r") if r == 15: print("testing results...") print("BRAVO, you have winned the game") else: print("testing results...") print("you have lost the game") elif a == "no": sys.exit("you said to do it") else: print("!!ERROR: you need to enter yes or no. !!") yes() yes()ERROR:
Error: File "C:\Users\Shishi\Desktop\QuizWorld\risultati\game.py", line 21
with open("lista risultati.txt", 'w') as f
^
SyntaxError: invalid syntax