(1) 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. 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. (3) Output the max list element with two digits after the decimal point. 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] Average weight: 166.95 Max weight: 236.00 (4) Prompt the user for a number between 1 and 4. Output the weight at the user specified location and the corresponding value in kilograms. 1 kilogram is equal to 2.2 pounds. Ex: Enter a list location (1 - 4): 3 Weight in pounds: 176.00 Weight in kilograms: 80.00 (5) Sort the list's elements from least heavy to heaviest weight. Ex: Sorted list: [89.5, 166.3, 176.0, 236.0] Output the average and max weights as floating-point values with two digits after the decimal point, which can be achieved as follows: print('{:.2f}'.format(your_value)) My Code: wt = [] for i in range(4): val = float(input('Enter weight ' + str(i+1) + ": ")) wt.append(val) print('Weights:', wt) total = 0.0 for i in range(len(wt)): total = total + wt[i] avg = total / len(wt); print('Average weight:{:.2f}'.format(avg)) max = wt[0] for i in range(len(wt)): if wt[i] > max: max = wt[i] print('Max Weight:{:.2f}'.format(max)) ind = int(input('Enter a list index location (1 - 4):')) if ind < 1 or ind > 4: print('Invalid index!') else: print('Weight in pounds:', wt[ind-1]) print('Weight in kilograms:', (wt[ind-1]/2.2)) for i in range(len(wt)): min_Pos = i for j in range(i + 1, len(wt)): if wt[j] < wt[min_Pos]: min_Pos = j if i != min_Pos: temp = wt[i] wt[i] = wt[min_Pos] wt[min_Pos] = temp print('Sorted list:', wt) This codes ouput: Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Weights: [236.0, 89.5, 176.0, 166.3] Average weight:166.95 Max Weight:236.00 Enter a list index location (1 - 4): Weight in pounds: 176.0 Weight in kilograms: 80.0 Sorted list: [89.5, 166.3, 176.0, 236.0] output should be: 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] Average weight: 166.95 Max weight: 236.00 Enter a list location (1 - 4): 3 Weight in pounds: 176.00 Weight in kilograms: 80.00 *The "enter weight" should be on a new line for each entry and not on the same line. as well as printing the number entered.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

(1) 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. 

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.

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

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] Average weight: 166.95 Max weight: 236.00

(4) Prompt the user for a number between 1 and 4. Output the weight at the user specified location and the corresponding value in kilograms. 1 kilogram is equal to 2.2 pounds.

Ex:

Enter a list location (1 - 4): 3 Weight in pounds: 176.00 Weight in kilograms: 80.00

(5) Sort the list's elements from least heavy to heaviest weight. 

Ex:

Sorted list: [89.5, 166.3, 176.0, 236.0]

Output the average and max weights as floating-point values with two digits after the decimal point, which can be achieved as follows:
print('{:.2f}'.format(your_value))

My Code:

wt = []

for i in range(4):
val = float(input('Enter weight ' + str(i+1) + ": "))
wt.append(val)
print('Weights:', wt)

total = 0.0

for i in range(len(wt)):
total = total + wt[i]
avg = total / len(wt);
print('Average weight:{:.2f}'.format(avg))

max = wt[0]

for i in range(len(wt)):
if wt[i] > max:
max = wt[i]
print('Max Weight:{:.2f}'.format(max))

ind = int(input('Enter a list index location (1 - 4):'))


if ind < 1 or ind > 4:
print('Invalid index!')

else:
print('Weight in pounds:', wt[ind-1])

print('Weight in kilograms:', (wt[ind-1]/2.2))


for i in range(len(wt)):
min_Pos = i
for j in range(i + 1, len(wt)):
if wt[j] < wt[min_Pos]:
min_Pos = j
if i != min_Pos:
temp = wt[i]
wt[i] = wt[min_Pos]
wt[min_Pos] = temp


print('Sorted list:', wt)

This codes ouput:

Enter weight 1: Enter weight 2: Enter weight 3: Enter weight 4: Weights: [236.0, 89.5, 176.0, 166.3]

Average weight:166.95

Max Weight:236.00

Enter a list index location (1 - 4):

Weight in pounds: 176.0

Weight in kilograms: 80.0

Sorted list: [89.5, 166.3, 176.0, 236.0]

 

output should be:

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]

 

Average weight: 166.95

Max weight: 236.00

Enter a list location (1 - 4): 3

Weight in pounds: 176.00

Weight in kilograms: 80.00

*The "enter weight" should be on a new line for each entry and not on the same line. as well as printing the number entered. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education