Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def nameMedals(last, first):
- gold = int('0')
- silver = int('0')
- bronze = int('0')
- lastflag = False
- firstflag = False
- flag = False
- with open("athletes.txt", encoding= 'utf-8') as file:
- for line in file:
- line = line.strip()
- if line == last.upper() or line == last.lower():
- lastflag = True
- elif line == first.upper() or line == last.lower():
- firstflag == True
- elif lastflag == True and firstflag == True:
- flag = True
- if line == '1':
- gold +=1
- elif line == '2':
- silver +=1
- elif line == '3':
- bronze +=1
- flag = False
- lastflag = False
- firstflag = False
- elif lastflag == False or firstflag == False:
- print("The name you specified is incorrect or is not in the data.")
- return
- return print(first + ' ' + last + ' won ' + str(gold) + ' gold medals, ' + str(silver) + ' silver medals, ' + str(bronze) + ' and bronze medals.')
- def main():
- last = input('Enter the last name of an athlete: ')
- first = input('Enter the first name of the same said athlete: ')
- nameMedals(last, first)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement