## Quiz Part 6_Save_scores_to_text_file.py

Sign up Free. Don't forget to check out our challenges, lessons, solve and learn series and more ...

## Code Snippet

``````#-------------------------------------------------------------------------------
# Name:       Maths Quiz
# Purpose:    Tutoral
# Author:     teachingcomputing.com
# Created:     23/02/2016

#-------------------------------------------------------------------------------

""" File Structure
scores.txt
===========
user1,1
user2,3
user3,1

"""
def quiz():
import random

score=0
operators=("x", "+", "-")
valid_name=False
found_number=False
numbers="123456789"

#Test score file - connecting (w = write - this simply creates a scores text file)
#myFile=open("scores.txt","w")
#a = append. (add scores to - rather than over write what is already there)
myFile=open("scores.txt","a")
myFile.close()

while valid_name==False:

found_number=False
name=input("Hi there, what is your name?: ")

for i in name:

for u in numbers:
if i==u:
found_number=True

if found_number==True:
valid_name=False
print("Invalid Name - Try again, without any numbers")

elif found_number==False:
valid_name=True
break

print("Great...let's start the quiz")
print("*********************************************")

for i in range(3):

num1=random.randint(5,10)
num2=random.randint(1,5)

operator=random.choice(operators)

if operator=="+":
elif operator=="-":
elif operator=="x":

print('What is ' + str(num1)+operator+str(num2))

print("That's Right")

score=score+1
else: