The program below asks the user to enter several integers, which are added to a list called values. Use the core math functions to find and display the minimum and maximum values and the sum of all entered values.
Use min() to find the minimum value. Print that minimum to the screen with the message "Min = [value]"
Use max() to find the maximum value. Print that maximum to the screen with the message "Max = [value]"
Use sum() to find the sum of all values. Print that sum to the screen with the message "Sum = [value]"
The following examples demonstrate the expected program output.
Enter list value: 2
Enter list value: 1
Enter list value: 3
Min = 1
Max = 3
Sum = 6
Enter list value: -10
Enter list value: 200
Enter list value: 30
Min = -10
Max = 200
Sum = 220
import math
values = []
for i in range(0,3):
value = int(input("Enter list value: "))
values.append(value)
min_value = min(values)
max_value = max(values)
sum_value = sum(values)
print("Min = ", min_value)
print("Max = ", max_value)
print("Sum = ", sum_value)
Are there supposed to be indentation?
9 answers
```python
import math
values = []
for i in range(0, 3):
value = int(input("Enter list value: "))
values.append(value)
min_value = min(values)
max_value = max(values)
sum_value = sum(values)
print("Min = ", min_value)
print("Max = ", max_value)
print("Sum = ", sum_value)
```
This code will correctly prompt the user to enter integer values, store them in a list, and then use the min(), max(), and sum() functions to find the minimum, maximum, and sum of the entered values. Finally, it will display these values with appropriate messages.
1. The `value = int(input("Enter list value: "))` line inside the `for` loop.
2. The `values.append(value)` line inside the `for` loop.
3. The `print("Min = ", min_value)` line.
4. The `print("Max = ", max_value)` line.
5. The `print("Sum = ", sum_value)` line.
These lines should be indented to the same level as the `for` loop statement to ensure that they are executed within the loop. Python uses indentation to define the structure of the code, so correct indentation is essential for the program to work correctly.
1. The line `value = int(input("Enter list value: "))` inside the `for` loop needs to be indented once.
2. The line `values.append(value)` inside the `for` loop needs to be indented once.
3. The line `print("Min = ", min_value)` outside the `for` loop needs no additional indentation.
4. The line `print("Max = ", max_value)` outside the `for` loop needs no additional indentation.
5. The line `print("Sum = ", sum_value)` outside the `for` loop needs no additional indentation.
Therefore, the lines inside the `for` loop need to be indented once, while the lines outside the `for` loop do not need any additional indentation.
In the provided code snippet, all indented lines (inside the `for` loop) should have 4 spaces before the code starts. The lines outside the loop should not have any additional indentation.
Here is the breakdown:
1. The line `value = int(input("Enter list value: "))` inside the `for` loop should be preceded by 4 spaces.
2. The line `values.append(value)` inside the `for` loop should also be preceded by 4 spaces.
The print statements outside the loop do not require additional indentation and should start at the beginning of the line.