Reputation: 9
I am making a program where the computer asks the user to enter a number and keeps asking until a blank line is entered. Every time a value is entered it checks if it is a number. If it is, then, it will append it to a list. Once a blank line is entered, it will print all the numbers and prime numbers.
The problem I am having is that I can't make the number an 'int' and a 'string' at the same time. Every time I make the number an 'int' it gives me this error: AttributeError: 'int' object has no attribute 'append' and every time I make it a 'str' it gives me this error:
TypeError: '>' not supported between instances of 'str' and 'int'
How can I make the code work?
Here is the code (what I have done so far... Not finished yet):
even_no = []
print('Prime Calculator')
# Ask for user to input number
number = int(input('Enter a number: '))
while number:
number = str(number)
#number = int(number)
if number > 1:
number.append(even_no)
number.append(even_no)
else:
print('Please enter number bigger than 1')
number = (input('Enter a number: '))
Upvotes: 0
Views: 736
Reputation: 10667
If you want to append something to a list, you write l.append(something)
and not the converse. So
number.append(even_no)
Should be replaced by
even_no.append(number)
Upvotes: 1