Problem 3 A radar speed gun is a device used in law-enforceme✗measure the speed of moving vehicles in miles per hour. The measured speeds are supposed to be stored in a file, one number per line, as follows: 65.6 70.2 54.9 Unfortunately, due to an intermittent fault, occasionally multiple numbers are written on a single line as follows: 73.2 65.6 69.8 Furthermore, occasionally the radar gun outputs a single stray character such as: 67.9z, 6$4.9, or a3.9, to illustrate just a few. Given a file that has radar speed gun readings, write a function averageSpeed() to calculate the average of the numbers in the file. Your code must adhere to the following specifications: a. Prompt the user for the name of the input file to process. When the user enters a nonexistent file name, give the user a second chance. After two wrong entries in a row, quit the program with an appropriate message. b. Ignore numbers containing stray characters. Ignore any reading for slow vehicles moving at 2 miles per hour or less. C. d. Print the final average to the console. e. Make use of the functions safeOpen() and safeFloat(). For example, the following is correct input/output: >>> inputFile = open('radar.txt') >>> content = inputFile.read() >>> print(content) 35.2 1.8 65.6 67.9z 70.2 73.2 a3.9 65.6 69.8 6$4.9 54.9 >>> inputFile.close() >>> >>> averageSpeed() Enter file name: ghost.txt File not found. Please try again. Enter file name: phantom.txt File not found. Yet another human error. Goodbye. >>> >>> averageSpeed >>> Enter file name: radar.txt >>> Average speed is 62.07 miles per hour. >>>
Problem 3 A radar speed gun is a device used in law-enforceme✗measure the speed of moving vehicles in miles per hour. The measured speeds are supposed to be stored in a file, one number per line, as follows: 65.6 70.2 54.9 Unfortunately, due to an intermittent fault, occasionally multiple numbers are written on a single line as follows: 73.2 65.6 69.8 Furthermore, occasionally the radar gun outputs a single stray character such as: 67.9z, 6$4.9, or a3.9, to illustrate just a few. Given a file that has radar speed gun readings, write a function averageSpeed() to calculate the average of the numbers in the file. Your code must adhere to the following specifications: a. Prompt the user for the name of the input file to process. When the user enters a nonexistent file name, give the user a second chance. After two wrong entries in a row, quit the program with an appropriate message. b. Ignore numbers containing stray characters. Ignore any reading for slow vehicles moving at 2 miles per hour or less. C. d. Print the final average to the console. e. Make use of the functions safeOpen() and safeFloat(). For example, the following is correct input/output: >>> inputFile = open('radar.txt') >>> content = inputFile.read() >>> print(content) 35.2 1.8 65.6 67.9z 70.2 73.2 a3.9 65.6 69.8 6$4.9 54.9 >>> inputFile.close() >>> >>> averageSpeed() Enter file name: ghost.txt File not found. Please try again. Enter file name: phantom.txt File not found. Yet another human error. Goodbye. >>> >>> averageSpeed >>> Enter file name: radar.txt >>> Average speed is 62.07 miles per hour. >>>
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,