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
there are these numbers that I've seen before but I don't know what they mean can someone help. I will give brainiest
Ne4ueva [31]

Answer:

Those numberss are binary code

Explanation:

Computers use binary - the digits 0 and 1 - to store data. A binary digit, or bit , is the smallest unit of data in computing. It is represented by a 0 or a 1. Binary numbers are made up of binary digits (bits), eg the binary number 1001.

5 0
3 years ago
Read 2 more answers
Why does your e-learning course need a title slide?
aev [14]

Answer:

You've probably noticed that many e-learning courses start with a title slide. ... Your title slide is important because it's the first impression users get of your course—and learners do judge e-learning courses within moments of launching them! So take the opportunity to captivate them with a great-looking title slide.

5 0
3 years ago
Read 2 more answers
Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp
slavikrds [6]

Answer:

Here are the for loop for the given question.

 for (i = 0; i < NUM_VALS; i++)  // for loop

       {

         /* check if the value of i is equal to NUM_VALS or not.If it is

         equal then just print the value without comma.*/

       if(i==(NUM_VALS-1))  // if block

       System.out.print(hourlyTemp[i]);

  /* if i is not equal then just print the value with comma.*/

       else   // else block

       System.out.print(hourlyTemp[i] + ", ");

       }

Explanation:

In this we iterating the for loop  and check the condition

check if the value of i is equal to NUM_VALS or not.If it is  equal then just print the value without comma

If i is not equal then just print the value with comma .

Output:

90,92,94,95

3 0
3 years ago
What process sends ones and zeroes across network cables
sergejj [24]

Answer:

modulation

Explanation:

Modulation is the procedure of encoding data into electrical signals for transmission through a media. For transmission, binary information, denoted by a sequence of ones and zeros, should be translated to analog or digital electrical signals. The method converts data into electrical signals suited for transmission is known as modulation.  Digital modulation is the transmission of binary signals zeroes and ones.

5 0
2 years ago
The security manager assigned a new security administrator the task of implementing secure protocols on all wireless access poin
Marysya12 [62]

Answer:

Good choice, as its one of the most secure wireless communications encryption methods, even though WPA2 would be the best

Explanation:

8 0
4 years ago
Other questions:
  • Select the correct answer.
    8·2 answers
  • Why does esherick say the name of the boxer rebellion in inaccurate
    5·1 answer
  • You have just made changes to a GPO that you want to take effect as soon as possible on several user and computer accounts in th
    7·1 answer
  • Before you enable data deduplication, what tool can you use to determine if data deduplication would benefit the tested volumes
    11·1 answer
  • What do people in japan use to make anime
    5·1 answer
  • You are part of an Information Systems project team. Your job is to ensure that the technology and vendor suggested for use in t
    12·1 answer
  • What is information processing cycle​
    12·1 answer
  • Which views can be used to see appointments in Outlook 2016? Check all that apply. Today Tomorrow Next 7 Days Work Week Two Week
    13·1 answer
  • Jim wants to shoot a video. This requires him to move from one place to another. Which type of camera support should Jim use?
    13·1 answer
  • In Python, which comparison operator means "less than or equal to"?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!