Question

A. Write a Python script so that the user can enter any number of grades. Create...

A. Write a Python script so that the user can enter any number of grades. Create a calcavg() function so that it takes the number of grades as a parameter and returns the regular average (not a weighted average). You must loop through the grades for full credit. Add a try/except block so that if a non-numeric value is entered, you get the error message shown below. You cannot use lists.

Input:

c. python …\IT2430\FirstLastname\assign5-2.py 96.7 95.6 87.0

d. python …\IT2430\FirstLastname\assign5-2.py 79.9 79.0 79.7 56.2

e. python …\IT2430\FirstLastname\assign5-2.py 79.0 70.0 stuff

Output:

c. Average: 93.100…

Letter Grade: A

d. Average: 73.7

Letter Grade: C

e. Error. Grade must be numeric.

B. Create a calcbmi() function that takes the height and weight as perimeters and computes a person's BMI at runtime (sys.argv). Create a getcategory() function that takes the BMI as a perimeter and returns the BMI category. The categories are as follows: BMI < 18.5 - underweight; BMI >= 18.5 and BMI <=25 - normal; BMI > 25 and BMI <=30 - overweight; BMI >= 31 - obese. The formula to calculate BMI is: (weight / (height * height ) ) * 703. You must loop through the heights and weights. Also, use a try/except block so an error message appears if the user tries to enter any non numeric input. You cannot use lists.

Input:

a. python …\IT2430\FirstLastname\assign5-3.py 65 120 70 170

b. python …\IT2430\FirstLastname\assign5-3.py 65 120 70

Output: a. BMI: 19.9668…

BMI category is normal.

BMI: 24.3897…

BMI category is normal.

b. Wrong number of arguments provided.

C. Write a script that calculates basic statistics from a list of quarterly sales using a function called calcstats(), that takes the quarterly sales as parameters and prints the outputs shown below. This function should work with any number of sales entered.  Use a try/except block to ensure that all numbers are entered. In addition, ensure that there are the correct number of arguments provided. You cannot use lists.

Input:

a. python …\IT2430\FirstLastname\assign5-4.py 200 100 300 400

b. python …\IT2430\FirstLastname\assign5-4.py 200 100

c. python …\IT2430\FirstLastname\assign5-4.py 200 100 stuff 400 500

Output:

a. Min: $100

Max: $400

Range: $300

Average: $250

b. Min: $100

Max: $200

Range: $100

Average: $150

c. All inputs should be numeric.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

PYTHON CODE:

# Import sys module to read command line arguments using sys.argv
import sys

# calcavg function to return average of grades
def calcavg(n):
   avg = 0
   try:
      # Loop through each grade in command line arguments
      for i in range(1, n + 1):
         avg += float(sys.argv[i])
      # Return average
      return avg / n
   except ValueError:
      print('Error. Grade must be numeric')
      return None

# Call calcavg with number of grades
avg = calcavg(len(sys.argv) - 1)
# Only print if function returned a grade
if avg is not None:
   print('Average:',avg)
   if avg >= 90:
      print('Letter Grade: A')
   elif avg >= 80:
      print('Letter Grade: B')
   elif avg >= 70:
      print('Letter Grade: C')
   elif avg >= 60:
      print('Letter Grade: D')
   else:
      print('Letter Grade: F')

CODE SCREENSHOT:

SAMPLE OUTPUTS:

Add a comment
Know the answer?
Add Answer to:
A. Write a Python script so that the user can enter any number of grades. Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this code is not working for me.. if enter 100 it is not showing the grades...

    this code is not working for me.. if enter 100 it is not showing the grades insted asking for score again.. #Python program that prompts user to enter the valuesof grddes . Then calculate the total scores , #then find average of total score. Then find the letter grade of the average score. Display the #results on python console. #grades.py def main(): #declare a list to store grade values grades=[] repeat=True #Set variables to zero total=0 counter=0 average=0 gradeLetter='' #Repeat...

  • Write a program that computes the average of a set of grades. The user is prompted...

    Write a program that computes the average of a set of grades. The user is prompted the following: 1-Number of grades to be entered. 2-The value of the minimum grade. 3-The value of the maximum grade. Make sure to write input validation for the following: 1-The number of grades cannot be negative! In case it is 0, it means that user has no grades to enter. 2-Each entered grade should be a valid grade between the minimum and maximum values...

  • in Python: Write a program that allows the user to enter a number between 1-5 and...

    in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...

    Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...

  • C++ Grades . Write a program that uses enum types to assign letter grades that can...

    C++ Grades . Write a program that uses enum types to assign letter grades that can be automatically converted to numerical grades. For this assignment, you'll create an enum type with the values F, D, C, B, and A, so the letter grades are associated with ordinal values 0, 1, 2, 3, and 4, respectively (which coincide with the quality points for that grade). Write a method assignCourseGrade(double grade) which takes a real number representing the grade for the class,...

  • USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by...

    USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv (PLEASE TYPE OUT ANSWER) Modify this program:...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv (PLEASE TYPE OUT ANSWER) Modify this program: Write a program to calculate the bmi getcategory(): takes the bmi as a parameter and returns the bmi category. You are not allowed to change the two functions and you will use the same two functions as previously. Just modify the program so that it calculates the bmi and category for any number of pairs of height and weights. You must loop through the...

  • QUESTION 21 while True: , in Python, can be used to create an infinite loop. True...

    QUESTION 21 while True: , in Python, can be used to create an infinite loop. True False 2 points    QUESTION 22 The Python Framework does inform you where an error occurred True False 2 points    QUESTION 23 ____ is a critical component to being able to store data and information long term. File Access Memory Print function with 2 points    QUESTION 24 Error handling is also known as ___ handling Result Recursion Exception Crash 2 points   ...

  • This is in C++. Example: You will write a program that will prompt the user to...

    This is in C++. Example: You will write a program that will prompt the user to enter a grade out of 100 and then show them what the equivalent grade points value is. The main() function will handle the input and output tasks, but the actual conversion will occur in a function called GradePoints(). GradePoints Specifications This function is strictly a processing function, meaning that there are no console input or output steps in the actual function. Consider that this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT