Assignment6.py - Michelle Gong Section 03 This program reads Olympic Games medal count data from a file and processes the data in several different ways

Assignment6.py - Michelle Gong Section 03 This program...

This preview shows page 1 - 2 out of 2 pages.

# Michelle Gong # Section 03 # This program reads Olympic Games medal count data from a file and processes # the data in several different ways # 11/19/19 # Get user input user_input = input('Please enter a data file name: ') # Opening files for reading or writing them olympic_games_data = open (user_input, 'r') outfile = open ('REPORT-' + user_input, 'w') # accumulators and counters total_nations = 0 any_kind_nations = 0 one_kind_nations = 0 total_gold = 0 total_bronze = 0 nation = olympic_games_data.readline() # priming read while (nation !=''): total_nations += 1 # update number of nations # Read lines from the file gold = int(olympic_games_data.readline()) silver = int(olympic_games_data.readline()) bronze = int(olympic_games_data.readline()) # Number of nations that won any kind of medal if not (gold==0 and silver==0 and bronze==0): any_kind_nations += 1 # Number of nations that won only one kind of medal if ((gold>0 and silver==0 and bronze==0) or (gold==0 and silver>0 and bronze==0) or (gold==0 and silver==0 and bronze>0)): one_kind_nations += 1 # The total number of medals a nation won
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Spring '16
  • goldner barbara

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes