CS 500 University Of Wisconsin Milwaukee Python Functions Finding Averages Lab

Question Description

Having Trouble Meeting Your Deadline?

Get your assignment on musc210 assignment 1 latest 2016 september completed on time. avoid delay and – ORDER NOW

A. Create a function called factorial that accepts an integer as an argument and returns the factorial of that integer. Do not print out anything in the factorial function. If the factorial function is called with a negative integer, a -1 is returned from the function. Do not prompt the user to enter a value. This will be taken care of by the tester program. Do not put anything else in this file except the factorial function (i.e. don’t put tester code in this file)

Make sure your function definition looks like this: def factorial(val):

B. Create a program that reads in integers and outputs the average of all of the numbers.

Some things to note:

  • Only integers will appear in the input file.
  • All of the integers in the input file will be separated by a space.
  • All integers will be on a single line.
  • Create a separate file called second.py to solve this problem.
  • Do not read in from a specific file. If you are using the open function, you are doing this problem wrong.

C. create a Python program that reads in 2 integers that are separated by a space. There will only be 2 integers in the input file. Your program then prints out all of the prime numbers strictly between those 2 numbers in increasing order. If there are no prime numbers strictly between those 2 numbers, then a No Primes message is printed out. The order that the numbers were input does not matter.


Output: If there are no primes between the two numbers, your code outputs exactly:

No Primes

If there is one prime number, only that 1 number prints out.

If there are multiple prime numbers, the following pattern is used:


In other words, you separate the first number from the second number with a colon. You separate the second number from the third number with an exclamation point. You separate the third number from the fourth number with an ampersand. This delimiter pattern is repeated in subsequent numbers (colon, exclamation point, ampersand) until there are no more numbers left to be printed. There is no delimiter before the first element nor is there a delimiter after the last element. The numbers in the output should be in numerical order.

D. You are a manager for a global weather company and you have asked your regional offices to send you information in the following comma separated format:


All offices put a header row in each file to explain the data. A key thing is that the temperature should have been in Fahrenheit and located in the second to last column. Another key thing is that the wind should have been located in the last column and should have been in miles per hour. None of the offices sent the data exactly how you asked for it. Your job is to figure out what each of them did and then answer the following 2 questions:

  1. Take the average of all of the wind speeds for March, 2006. Which city had the closest wind speed to 8.30 mph?
  2. Take the average of all of the temperatures for 2006. Which city had the closest temperature, in fahrenheit, to 49.65.

The 4 cities are ABC, KLM, PQR and XYZ (see filenames). The way you clean the data and obtain the answers is entirely up to you with a couple of caveats. Any wind speed that is negative should be filtered out as this is not possible. Any temperature below -200 should be filtered out. Any wind speed that is listed as calm should be interpreted as 0mph or 0kph depending on the column header. Calm winds should not be filtered out. When filtering out data, only filter out the cell that is invalid, not the entire row. For example, if a row has a temperature of -9999 and a wind of 7.8, filter out the temperature but keep the wind value.

For this dirty data task, you only need to create a text file called answers.txt that contains the answer to each of the above questions. Any reasonable formatting of answers.txt is acceptable. You do not need to upload any code or explain how you obtained your answers for this final question.




Order Solution Now

Similar Posts