I'm using python and I'm unable to find out how to get python to alert a user when he gives an integer as an input, that has already been entered. Also for some reason I am not able to find the sum of a list let alone the mean. Here is what I have so far tried. I want a user to be able to enter 10 integers.
value = raw_input ("Enter a number: ")
numbers = [(x) for x in value.split()]
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
numbers.append (raw_input("Enter a number: "))
print sum(numbers)/len(numbers)
This allows a user to make a list and when I print the list, it comes out fine
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9
Enter a number: 8
>>> print numbers
['1', '2', '3', '4', '5', '6', '7', '8', '9', '8']
Now when I use this code to find the sum or even the mean.
print sum(numbers)/len(numbers)
After the user enters the 10 numbers, this comes out
Traceback (most recent call last):
File "C:/Python27/need help.py", line 13, in <module>
print sum(numbers)/ len (numbers)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
also is there a way to alert the user when they have entered a duplicate number?
Please I really need help.
You haven't converted the input into integers. They are still strings.
Use this to convert them -