Help! I'm a starter coder and I am trying to build a top trumps game. I have created an external CSV file that stores the scores of the game. I am trying to get the game to print the highest score recorded but I am running in to a lot of errors. SOMEONE PLEASE HELP :(. I've been working on this for days now and the code keeps breaking more and more every time i try to fix it.
import random
import requests
import csv
def random_person():
person_number = random.randint(1, 82)
url = 'https://swapi.dev/api/people/{}/'.format(person_number)
response = requests.get(url)
person = response.json()
return {
'name': person['name'],
'height': person['height'],
'mass': person['mass'],
'birth year': person['birth_year'],
}
def run():
highest_score = 0
with open('score.csv', 'r') as csv_file:
spreadsheet = csv.DictReader(csv_file)
for row in spreadsheet:
intscore = int(row['score'])
if intscore > highest_score:
highest_score = intscore
print('The highest score to beat is', highest_score)
game = input('Do you think you can beat it? y/n')
if game == 'y':
print('Good Luck