Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts)

Ex:

Enter weight 1:
236.0
Enter weight 2:
89.5
Enter weight 3:
176.0
Enter weight 4:
166.3
Weights: [236.0, 89.5, 176.0, 166.3]
(2) Output the average of the list's elements with two digits after the decimal point. Hint: Use a conversion specifier to output with a certain number of digits after the decimal point. (1 pt)

(3) Output the max list element with two digits after the decimal point. (1 pt)

Respuesta :

Answer:

# FIXME (1): Prompt for four weights. Add all weights to a list. Output list.

weight_one=float(input('Enter weight 1:\n'))

weight_two=float(input('Enter weight 2:\n'))

weight_three=float(input('Enter weight 3:\n'))

weight_four=float(input('Enter weight 4:\n'))

weights=[weight_one,weight_two,weight_three,weight_four]

print(weights)

# FIXME (2): Output average of weights.

average_weight=(weight_one + weight_two + weight_three + weight_four) / 4

print('Average weight:', "%.2f" % average_weight)

# FIXME (3): Output max weight from list.

weights.sort()

max_weight= weights[3]

print('Max weight:', "%.2f" % max_weight)

# FIXME (4): Prompt the user for a list index and output that weight in pounds and kilograms.

print(input('Enter a list index location (0 - 3):'))

print('Weight in pounds:', weights)

kilograms = float(weights) * 2.2

print('Weight in kilograms:')

# FIXME (5): Sort the list and output it.

weights.sort()

print(weights)

Explanation:

The code that prompt the user to enter four numbers, each corresponding to a person's weight in pounds, print the average weight and maximum value is as follows:

a = float(input("Enter weight 1: "))

b = float(input("Enter weight 2: "))

c = float(input("Enter weight 3: "))

d = float(input("Enter weight 4: "))

list1 = [a, b, c, d]

print(list1)

average_weight = round(a + b + c + d / 2, 2)

print(average_weight)

print(max(list1))

Code explanation

The code is written in python.

  • The variable a, b, c, and d is used to store the users input.
  • The variable list1 stores the list value of the users inputs.
  • Then we print the list of the users input.
  • The variable "average_weight" is used to calculate and store the average weight of the users inputs and coverts it to 2 decimal places.
  • Then we print the average weight in 2 decimal places.
  • Finally, we print the maximum value of the list of  users input.

learn more on python here: https://brainly.com/question/15387391

Ver imagen vintechnology
Ver imagen vintechnology
ACCESS MORE