Question: So I need some help fixing something in Python language. I don't think details are required, just the code and the problem. This is my

So I need some help fixing something in Python language. I don't think details are required, just the code and the problem.

This is my code:

weights = []

for i in range(4): prompt = "Enter weight " + str(i+1) + ": "; val = float(input(prompt)) weights.append(val)

print(" Weights: ", end=""); print(weights)

avg = sum(weights) / len(weights); print("Average weight: " + str(avg))

print("Max weight: " + str(max(weights)))

index = int(input(" Enter a list index (1 - 4): "))

if index 4: print(" Invalid index!!! "); else: print(" Weight in pounds: " + str(weights[index-1]) + " Weight in kilograms: " + str(weights[index-1]*0.4546) + " ");

print("Sorted list: ", end=""); weights.sort() print(weights)

And this is the problem:

So I need some help fixing something in Python language. I don't

How do I go about changing the weight in kilograms to have just 1 decimal place?

I assume the following line from the code I gave is what I need to change, but I have little idea how to

print(" Weight in pounds: " + str(weights[index-1]) + " Weight in kilograms: " + str(weights[index-1]*0.4546) + " ");

6: Compare output 236 89.5 Input 176 166. 3 Enter weight 1: Enter weight 2: Enter weight 3 Enter weight 4: Weights [236.0, 89.5, 176.0, 166.31 Average weight: 166.95 Max weight: 236.0 Your output Enter a list index (1 - 4): Weight in pounds: 176.0 Weight in kilograms: 80.0096 Sorted list: [89.5, 166.3, 176.0, 236.0] Enter weight 1: Enter weight 2: Enter weight 3 Enter weight 4: Weights [236.0, 89.5, 176.0, 166.31 Average weight: 166.95 Expected output Max weight: 236.0 Enter a list index (1 - 4): Weight in pounds: 176.0 Weight in kilograms: 80.0 Sorted list: [89.5, 166.3, 176.0, 236.0]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!