- 1
Write a python program which will ask user to enter 3 numbers. Your program will output the sum and average of these 3numbers.your program will also output the largest number, the smallest number of these three. For exampleif user enter 2,10,3 than your program will output, For number 2,10,3 sum is 15,average is 5,the largest number is 10 and the smallest number is 2.
4 Respostas
+ 1
# you may want to experiment with float vs int
# to see the difference in allowed user input.
# also .format() is a useful feature for your problem.
user_num = input('Enter 3 number values as digits')
try:
data= sorted(map(float,user_num.split()))
print('''
The average value is {0}
The smallest is {1}
The largest is {2}
'''.format(sum(data)/len(data),data[0],data[-1]))
except:
print('some of your input is invalid')
- 1
Here's the code you're looking for:
nums = input("""input three numbers(comma and space separated)
>>> """)
nums = nums.split(", ")
nums = list(map(int, nums))
print("Sum: " + str(sum(nums)) + ", Average: " + str(sum(nums)/len(nums)) + ", Highest Number: " + str(max(nums)) + ", Lowest Number: " + str(min(nums)))
- 2
Is this a question?
- 2
If is it a question about lasagna or ravioli, I will answer it :) I am an expert🤗😄