couple of things in my python code. I'm working on files and exceptions 1. Line 15: There's a type error and I don't know how to change "numbers" from an str to an int 2. I have to execute two examples of this, one with the file_name golf.txt and the other without the file_name. But should I use FileNotFoundError, as it's typically used for files that don't exist and golf.txt does exist, or should I purposefully make a mistake writing
couple of things in my python code. I'm working on files and exceptions 1. Line 15: There's a type error and I don't know how to change "numbers" from an str to an int 2. I have to execute two examples of this, one with the file_name golf.txt and the other without the file_name. But should I use FileNotFoundError, as it's typically used for files that don't exist and golf.txt does exist, or should I purposefully make a mistake writing
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Hello I need help with a couple of things in my python code. I'm working on files and exceptions
1. Line 15: There's a type error and I don't know how to change "numbers" from an str to an int
2. I have to execute two examples of this, one with the file_name golf.txt and the other without the file_name. But should I use FileNotFoundError, as it's typically used for files that don't exist and golf.txt does exist, or should I purposefully make a mistake writing the file_name and then the except will print? Or is there a different error I should be using?
![▪ Include the following information as comments at the top of your program (file name, your name, today's date, short description of the program)
• Your program should read a file that contains a list of golf player names and their scores, and should find the best player based on the score (lower is better in golf).
▪ Create a file with contents as shown in Sample Input File below
• To create a data file - Click on the File menu bar, then click New Launcher, and finally click Text File inside the Others section. (Alternately you can click File on the menu bar, then click New and select Text File)
• Copy paste the contents to the file
▪ Click File - Save as, in the save as dialog box - Files of Type - select text file. Enter file name as golf.txt - save the file.
▪
Read a file name as user input (which you created in the previous step - golf.txt)
▪ Catch any problem opening the file. If problem occurs, print an error message and exit.
▪ (Use Exception Handler, save the exception error message to exception object and print the message)
• You must use a while-loop to read all the values from the golf.txt file.
▪ Using while-loop, display the contents of the file (as shown in Sample Input and Output below)
▪ count the number of players
▪ the winner is the player who made the lowest score.
▪ Display the total number of players, Display the winner (player with lowest score)
▪ Close the file.
. Make sure you have a main function and there should not be any global variable or statement other than main() function call is used.
Sample Input File:
Jose Maria Olazabal
73
Vijay Singh
75
Sandy Lyle
73
Mike Wein
73
Larry Mize
79
Bubba Watson
69
Bernhard Langer
70
Adam Scott
72
Fred Couples
75
Sample Input and Output:
Enter the name of the file to open for read: golf.txt
Jose Maria Olazabal 73
Vijay Singh 75
Sandy Lyle 73
Mike Weir 73
Larry Mize 79
Bubba Watson 69
Bernhard Langer 70
Adam Scott 72
Fred Couples 75
There are 9 players in file golf.txt
The winner of this tournament is Bubba Watson with the score of 69](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3eb03a80-7cae-4d33-b228-e2e0361c370e%2Fd82f5d34-336d-4a5d-ba72-6b52e99b3658%2F5s08wr0c_processed.png&w=3840&q=75)
Transcribed Image Text:▪ Include the following information as comments at the top of your program (file name, your name, today's date, short description of the program)
• Your program should read a file that contains a list of golf player names and their scores, and should find the best player based on the score (lower is better in golf).
▪ Create a file with contents as shown in Sample Input File below
• To create a data file - Click on the File menu bar, then click New Launcher, and finally click Text File inside the Others section. (Alternately you can click File on the menu bar, then click New and select Text File)
• Copy paste the contents to the file
▪ Click File - Save as, in the save as dialog box - Files of Type - select text file. Enter file name as golf.txt - save the file.
▪
Read a file name as user input (which you created in the previous step - golf.txt)
▪ Catch any problem opening the file. If problem occurs, print an error message and exit.
▪ (Use Exception Handler, save the exception error message to exception object and print the message)
• You must use a while-loop to read all the values from the golf.txt file.
▪ Using while-loop, display the contents of the file (as shown in Sample Input and Output below)
▪ count the number of players
▪ the winner is the player who made the lowest score.
▪ Display the total number of players, Display the winner (player with lowest score)
▪ Close the file.
. Make sure you have a main function and there should not be any global variable or statement other than main() function call is used.
Sample Input File:
Jose Maria Olazabal
73
Vijay Singh
75
Sandy Lyle
73
Mike Wein
73
Larry Mize
79
Bubba Watson
69
Bernhard Langer
70
Adam Scott
72
Fred Couples
75
Sample Input and Output:
Enter the name of the file to open for read: golf.txt
Jose Maria Olazabal 73
Vijay Singh 75
Sandy Lyle 73
Mike Weir 73
Larry Mize 79
Bubba Watson 69
Bernhard Langer 70
Adam Scott 72
Fred Couples 75
There are 9 players in file golf.txt
The winner of this tournament is Bubba Watson with the score of 69
![1 # Rahma Seid
2 # CSCI 1170-001
WN
3 # CLA19
4 # The purpose of the program is for the user to determine who's the best in golf
5
6 def main():
7
try:
co o
8
9
10
11
12
13
NP
14
in A
15
16
17
18
19
%
20
21
22
23
24
25
golf_file = open("golf.txt", "r")
name = golf_file.readline()
score = golf_file.readline()
min_value = 70
if ("score < min_value"):
min_value = score
min_name = name
for numbers in range("1, numbers+1"):
golf_file = float(input("Enter the name of the file to open for read:"))
hame.rstrip('\n')
name nam
print (f"{name}")
print (f"{score:.2f}")
line = golf_file.readline()
print (f"There are 9 players in file golf.txt.")
print (f"The winner of this touranment is {min_name} with a score of {min_value}.")
except FileNotFoundError:
print("No file was entered.")](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3eb03a80-7cae-4d33-b228-e2e0361c370e%2Fd82f5d34-336d-4a5d-ba72-6b52e99b3658%2Fiadkcln_processed.png&w=3840&q=75)
Transcribed Image Text:1 # Rahma Seid
2 # CSCI 1170-001
WN
3 # CLA19
4 # The purpose of the program is for the user to determine who's the best in golf
5
6 def main():
7
try:
co o
8
9
10
11
12
13
NP
14
in A
15
16
17
18
19
%
20
21
22
23
24
25
golf_file = open("golf.txt", "r")
name = golf_file.readline()
score = golf_file.readline()
min_value = 70
if ("score < min_value"):
min_value = score
min_name = name
for numbers in range("1, numbers+1"):
golf_file = float(input("Enter the name of the file to open for read:"))
hame.rstrip('\n')
name nam
print (f"{name}")
print (f"{score:.2f}")
line = golf_file.readline()
print (f"There are 9 players in file golf.txt.")
print (f"The winner of this touranment is {min_name} with a score of {min_value}.")
except FileNotFoundError:
print("No file was entered.")
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Hi. I tried the code but nothing came out in the output. Could you please recheck it?
![(base) jovyan@jupyter-rs8f:~$ python c19.py
(base) jovyan@jupyter-rs8f:~$](https://content.bartleby.com/qna-images/question/3eb03a80-7cae-4d33-b228-e2e0361c370e/4d239cfd-ebfb-48e7-aeda-6db9c3462cc0/xoii06i_thumbnail.png)
Transcribed Image Text:(base) jovyan@jupyter-rs8f:~$ python c19.py
(base) jovyan@jupyter-rs8f:~$
Solution
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education