I've got quite a problem with python right now. I try around to just calculate a few integers in an array. So it should not be too complicated. I worked on it over a 2 days now, but can't get it to work.
def calculate( str ):
global x
if (len(x)==9):
a = []
for i in x_str:
a.append(i)
print(a)
b = 0
for j in range(1,9):
if (type(a[j])==int):
b = b + (a[j] * j)
else:
print('Your x is not a number!')
print(b)
else:
print('Your x is too long or too short.')
isdn = input('Enter your x with 9 numbers')
calculate( x )
# Operation
x = input('How is your x?')
try:
x = str( x )
calculate( x )
except:
print('Not a String!')
I just want to input an integer with 9 numbers and change that to an array. And do a simple calculation then with it.
I tried to do it without that damn try and except first, but that does not work either. Somehow Python won't except that x is a string when I enter it with input. What can I do, to get this calculation to work? It keeps telling me:
SyntaxError: Non-ASCII character '\xe2' in file
I am really desperate right now, since I cannot get it to work.... Somehow Python is mixing strings and integers up and I cannot understand why. I know other languages, but never had that much trouble to get a simple calculation to work. Does anyone can point me out my mistake? Or what I can do?