I've written some code for a very basic quiz for a project, but whatever I do the program always outputs what I've set the variable to at the start. It seems to be choosing the right input, and the else statements work, so I can only assume I've done something wrong in the adding to "per" but I can't work out what Here's the code...
from random import randint
print(" How like xx are you? Take a test!")
print(" whats your name?")
appendMe = str(input())
input(" press enter to start")
global per
def T(per , a , b , qu):
per = (per + 0 )
print(" Input the letter of the answer you choose !")
print ( qu )
print ( a )
print ( b )
choice = str(input())
if choice == "A" :
per = int(per + 10)
elif choice == "B" :
per = int(per)
else:
print(" Input either A , B , C or D ... Lets try again...")
Q(per , a , b ,c ,d)
def Q(per , a , b ,c ,d):
per = (per + 0 )
cho = int(randint(0,2))
if cho == 1 :
print(" Input the letter of the answer you choose !")
print ( qu )
print ( a )
print ( b )
print ( c )
print ( d )
choice = str(input())
if choice == "A" :
per = int(per + 5)
elif choice == "B" :
per = int(per + 2)
elif choice == "C" :
per = int(per)
elif choice == "D" :
per = int(per )
else:
print(" Input either A , B , C or D ... Lets try again...")
Q(per , a , b ,c ,d)
else:
print(" Input the letter of the answer you choose !")
print ( qu )
print ( d )
print ( c )
print ( b )
print ( a )
choice = str(input())
if choice == "D" :
per = int(per + 5)
elif choice == "C" :
per = int(per + 2)
elif choice == "B" :
per = int(per )
elif choice == "A" :
per = int(per)
else:
print(" Input either A , B , C or D ... Lets try again...")
Q(per , a , b ,c ,d)
per = int(50)
qu = " What is/was/will be your favourite subject at school"
a = " Computer science "
b = " English"
c = " art"
d = " textiles"
print("You are " , per , "percent xx!")
appendFile = open(" exampleFile.txt" , "a")
appendFile.write("\n")
appendFile.write(appendMe )
appendFile.write(per)
appendFile.close()
perin both functions? try changing the name.globalshould be placed withing the functions, and you should not pass it as a parameter...