1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
VashaNatasha [74]
4 years ago
8

Recall that when the built-in function open() is called to open a file for reading, but it doesn't exist, an exception is raised

. However, if the file exists, a reference to the opened file object is returned. Write a function safeOpen() that takes one parameter, filename - a string giving the pathname of the file to be opened for reading. When safeOpen() is used to open a file, a reference to the opened file object should be returned if no exception is raised, just like for the open() function. If an exception is raised while trying to open the file, safeOpen() should return the value None. For example, assuming the file ghost.txt doesn't exist, the following is correct output: >>> # open() >>> print (open('ghost.txt')) Traceback (most recent call last): File "", line 1, in print(open('ghost.txt')) FileNotFoundError: [Errno 2] No such file or directory: 'ghost.txt >>> • safeOpen() >>> inputFile = safeOpen('ghost.txt') >>> print(inputFile) None >>> Problem 3 A radar speed gun is a device used in law-enforcement to 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.92, 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. c. Ignore any reading for slow vehicles moving at 2 miles per hour or less. 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 78.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.87 miles per hour def safeFloat (x): try: float (x) return True except ValueError: return false
Computers and Technology
1 answer:
Pie4 years ago
3 0

Answer:

could you shorten it a little?

Explanation:

You might be interested in
Which model allows you to make subsystems in parallel?
boyakko [2]
The model is Parallel Distributed Processing Model (PDP) wherein m<span>Memory results from weblike connections among interacting processing units operating simultaneously, rather than sequentially ( also known as the connectionist model).</span>
8 0
3 years ago
Under which of the following conditions will evaluating this boolean expression
zzz [600]
1.) 
<span>((i <= n) && (a[i] == 0)) || (((i >= n) && (a[i-1] == 0))) </span>

<span>The expression will be true IF the first part is true, or if the first part is false and the second part is true. This is because || uses "short circuit" evaluation. If the first term is true, then the second term is *never even evaluated*. </span>

<span>For || the expression is true if *either* part is true, and for && the expression is true only if *both* parts are true. </span>

<span>a.) (i <= n) || (i >= n) </span>

<span>This means that either, or both, of these terms is true. This isn't sufficient to make the original term true. </span>

<span>b.) (a[i] == 0) && (a[i-1] == 0) </span>

<span>This means that both of these terms are true. We substitute. </span>

<span>((i <= n) && true) || (((i >= n) && true)) </span>

<span>Remember that && is true only if both parts are true. So if you have x && true, then the truth depends entirely on x. Thus x && true is the same as just x. The above predicate reduces to: </span>

<span>(i <= n) || (i >= n) </span>

<span>This is clearly always true. </span>
3 0
3 years ago
What is the statement describing? Agile team continuously adapt to new circumstances and enhance the methods of value delivery
Vera_Pavlovna [14]

Answer:

Continuous Integration

Explanation:

In continuous integration process, A program or piece of code is edited, tested and validated by team of software developers or contributors to complete and deploy the single project. This practice will improve the quality and reliability of the code.

Improvement, delivery and deployment are the three different phases, to complete the process of continuous integration.The individuals who contribute in a code or program  in terms of improvement, delivery and deployment make a team that leads to continuous integration.

So, Agile team Continuously adapt Continuous Integration to new circumstances and enhance the methods of value delivery.

8 0
3 years ago
If you want to open an application that does not have a tile pinned to the start menu
guapka [62]
Search for it in the start menu. Once you find it, right click and press "Pin to taskbar."
6 0
3 years ago
Explain the difference between true north and magnetic north.
Furkat [3]
Magnetic north is the north a compass points in the direction of. True north, on the other hand, is north based on the earth's axis.
4 0
3 years ago
Other questions:
  • Create a stored procedure named prc_inv_amounts to update the INV_SUBTOTAL, INV_TAX, and INV_TOTAL. The procedure takes the invo
    8·1 answer
  • You just read an msds for acetic acid. based on what you read, what type of information is included in an msds sheet? record you
    7·1 answer
  • Webster defines risk as "the possibility of loss or injury". Therefore, driving a motor vehicle is a risk.
    12·1 answer
  • . The toasting cycle of an automatic toaster is started by A. pushing the bread rack down. B. pushing the start button. C. turni
    14·2 answers
  • assume that you want to sort an array have 100000 elements which algorithm (insert sort algorithm or quick sort algorithm) is th
    12·1 answer
  • How to download a software program??
    15·1 answer
  • Read the section, "Junior Year." Why would someone chose to complete an apprenticeship after high school? How many occupations c
    14·2 answers
  • A circle surrounding the earth at the equator would consist of ___________ “degrees” of angular measurement.
    15·1 answer
  • In Outlook 2016, the Tell Me function can be accessed by
    15·2 answers
  • A(n) _______________ is a network organization that centralizes user accounts, passwords, and access to resources.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!