Answer:
The program in Python is as follows:
num_weight = int(input("Weights: "))
Weights = []
totalweight = 0
for i in range(num_weight):
w = float(input("Weight "+str(i+1)+": "))
Weights.append(w)
totalweight+=w
print("Weights: ",Weights)
print('Average Weight: %.2f' % (totalweight/num_weight))
print('Maximum Weight: %.2f' % max(Weights))
num = int(input("Enter a number between 1 and "+str(num_weight)+": "))
print('Weight in kg: %.2f' % Weights[i-1])
print('Weight in lb: %.2f' % (Weights[i-1]/2.205))
Weights.sort()
print("Sorted weights: ",Weights)
weight_on_mars = []
for i in range(num_weight):
weight_on_mars.append(round((Weights[i]/9.81 * 3.711),1))
print("Weights on mars: ",weight_on_mars)
print("Congratulations")
Step-by-step explanation:
This gets the number of weights
num_weight = int(input("Weights: "))
This initializes the weights
Weights = []
This initializes the total weight to 0
totalweight = 0
The iterates through the number of weights
for i in range(num_weight):
This gets each weight
w = float(input("Weight "+str(i+1)+": "))
This appends the weight to the list
Weights.append(w)
This calculates the total weights
totalweight+=w
This prints all weights
print("Weights: ",Weights)
Calculate and print average weights to 2 decimal places
print('Average Weight: %.2f' % (totalweight/num_weight))
Calculate and print maximum weights to 2 decimal places
print('Maximum Weight: %.2f' % max(Weights))
Prompt the user for input between 1 and the number of weights
num = int(input("Enter a number between 1 and "+str(num_weight)+": "))
Print the weight at that location in kg and lb
print('Weight in kg: %.2f' % Weights[i-1])
print('Weight in lb: %.2f' % (Weights[i-1]/2.205))
Sort weights and print the sorted weights
Weights.sort()
print("Sorted weights: ",Weights)
Create a new list for weights on mars
weight_on_mars = []
The following populates the list for weights on mars
for i in range(num_weight):
weight_on_mars.append(round((Weights[i]/9.81 * 3.711),1))
Print the populated list
print("Weights on mars: ",weight_on_mars)
print("Congratulations")