Question

(please write code in Python and provide output) Write a program that reads the records from...

(please write code in Python and provide output)

Write a program that reads the records from the golf.txt file written in the previous exercise and prints them in the following format:

Name: Emily
Score: 30

Name: Mike
Score: 20

Name: Jonathan
Score: 23

Sample Run

Name:Jimmy↵
Score:30↵

Name:Carly↵
Score:20↵

Name:Marissa↵
Score:55↵

Name:Brett↵
Score:23↵

0 0
Add a comment Improve this question Transcribed image text
Answer #1
try:
    with open('golf.txt') as r:
        lines = r.readlines()
        for i in range(0, len(lines), 2):
            print("Name:", lines[i].strip())
            print("Score:", lines[i+1].strip())
            print()
except FileNotFoundError:
    print("golf.txt is not found!")

Add a comment
Know the answer?
Add Answer to:
(please write code in Python and provide output) Write a program that reads the records from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you...

    The Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you to write a program that will read each player's name and score as keyboard input, and then save these as records in a file named golf.txt. First, have the program ask the user how many players they want to add to their record. Then, ask the user for each name and score individually. golf.txt should be structured so that there is a line with...

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Help me write a python code. Write a program that asks the user for the name...

    Help me write a python code. Write a program that asks the user for the name of a text file, then reads each line of the text file and prints it on the screen, making every other line "title case." For example, suppose the following text is saved in my_file.txt: While I nodded, nearly napping Suddenly there came a tapping As of someone gently rapping, Rapping at my chamber door. When run, the program looks like this: Enter filename: While...

  • Assignment Modify the code Binary File IO Example Code. The code reads and prints information abo...

    In java Assignment Modify the code Binary File IO Example Code. The code reads and prints information about a BMP file. Modify the code so that it also prints the resolution of the BMP file (both width and height) and the number of bits per pixel. Do not use any Java library or third-party library code that reads BMP files. You must read the file using simple Java code and extract the information, similar to the code in the example....

  • In python Please type the code Question 4: Write a program that reads an English word...

    In python Please type the code Question 4: Write a program that reads an English word from the user, and prints how many vowels and how many consonants it contains. Note: You may assume the letter Y is not a vowel. Sample output (2 different executions) Enter a word: test test has 1 vowels and 3 consonants Enter a word: Apple Apple has 2 vowels and 3 consonants.

  • python Write a program that reads the name of fruits and the colors from an input...

    python Write a program that reads the name of fruits and the colors from an input file fruit. txt. Each fruit name and the color is given on a line as shown below separated by space Apple Red Orange Orange Grape Green Now write output to an output file (fruit2.txt) as shown below Color of Apple is Red Color of Orange is Orange Color of Grape is Green The program has to be general to read in as many lines...

  • (Count the occurrences of each keyword) Write a python program that reads in a Python source...

    (Count the occurrences of each keyword) Write a python program that reads in a Python source code file and counts the occurrence of each keyword in the file. Your program should prompt the user to enter the Python source code filename.

  • In Python Provide me with your code file, output file and the text file Create a...

    In Python Provide me with your code file, output file and the text file Create a file having different integers than the first one. Save it as numbers1. txt . Write a program that reads all the number and calculates their average. Important: The two files that you are creating will contain different numbers.

  • Write a PYTHON program that reads a file (prompt user for the input file name) containing...

    Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1   0.5 2   0.5 3   0.5 4   0.5 The output should be:    The averages are 2.50 and 0.5. a)   Your code with comments b)   A screenshot of the execution Version 3.7.2

  • This needs to be linux compatible in C++ code. Write a program that reads a file...

    This needs to be linux compatible in C++ code. Write a program that reads a file consisting of students’ test scores in the range 0–200. It should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. Output the score ranges and the number of students. (Run your program with the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT