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
Whats your favorite thing about tech
Lera25 [3.4K]
How it advances our lives and helps us in so many ways
5 0
3 years ago
Read 2 more answers
Mobile Device Managment includes all of the following except
Gemiola [76]

Answer: Physical damage protection

Explanation:

Mobile device management included all the above mention features except physical damage protection as, mobile management system do not responsible for any physical damage.

Mobile device management system are only responsible for protection of the various mobile devices, app security and also provide data transmission protection.

As, there is no policy in the mobile device management system which include any type protection from physical damage. It is only responsible for control data error in the devices and software protection.

7 0
3 years ago
Create an ArrayList of strings to store the names of celebrities and athletes. Add 5 names to the list. Process the list with a
mr Goodwill [35]

Answer:

// ArrayList class is imported

import java.util.ArrayList;

// Iterator class is imported

import java.util.Iterator;

// Main class is defined

class Main {

   // main method to begin program execution

   public static void main(String args[]) {

       // names ArrayList of String is defined

       ArrayList<String> names = new ArrayList<>();

       // 5 names are added to the list

       names.add("John");

       names.add("Jonny");

       names.add("James");

       names.add("Joe");

       names.add("Jolly");

       // for loop to print the names inside the arraylist

       for(int index = 0; index <names.size(); index++){

         System.out.println(names.get(index));

       }

       

       // A blank line is printed

       System.out.println();

       // A newMethod is called with names as argument

       newMethod(names);

       // A blank line is printed

       System.out.println();

       // Instance of Iterator class is created on names

       Iterator<String> iter

           = names.iterator();

 

       // Displaying the names after iterating

       // through the list

       while (iter.hasNext()) {

           System.out.println(iter.next());

       }

   }

   // the newmethod is created here

   public static void newMethod(ArrayList<String> inputArray){

     // A new name is added at index 2

     inputArray.add(2, "Smith");

     // the name in index 4 is removed

     inputArray.remove(4);

     // for each is used to loop the list and print

     for (String name : inputArray) {

       System.out.println(name);

       }

   }

}

Explanation:

The code is well commented. An output image is attached.

7 0
4 years ago
How do u friend ppl on iPhone and do I need to be at a certain level to do so?
andrey2020 [161]
Launch the game center app , tap on the friends tab , <span>tap the </span>plus sign in the upper left hand corner , <span>type in their cgme center id , then send . </span>
3 0
4 years ago
Internet service providers​ (isp) need to resolve customer problems as quickly as possible. for one​ isp, past data indicates th
I am Lyosha [343]
I think that the likelihood will still be 0.8 as that means that 8 out of 10 calls will be resolved within one hour so the 7 out of 10 falls within that likelihood so therefore the callers can go by that assumption and be fairly confident that they have quite a high likelihood of having their problems resolved within one hour.
3 0
3 years ago
Read 2 more answers
Other questions:
  • How to help it automation with python professional certificate?
    10·1 answer
  • which is a set of techniques that use descriptive data and forecasts to identify the decisions most likely to result in the best
    8·1 answer
  • One way to prepare for filing the PROFILE is to:
    12·2 answers
  • If you are trying to improve your budget and spending, which option would save you the most money?
    13·2 answers
  • 12. Realizar un algoritmo que genere un número aleatorio, el usuario debe adivinar cual es el número generado para esto tendrá 3
    10·1 answer
  • Type the correct answer in the box. Spell the word correctly.
    15·2 answers
  • Select the correct answer.
    9·1 answer
  • Which of the following is true of lossy and lossless compression algorithms?
    11·1 answer
  • Como se juega robótica de cokitos
    13·1 answer
  • Write a python program to calculate the sum of three numbers and as well require the user to input the numbers.​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!