I'm starting to program in Python, and my question is this:
my program does run, however when wanting to exit the loop, it throws me the following error:
def pcn_loop3():
while True:
x = int(input("Ingrese un numero ('*' para terminar): "))
if x == '*':
break
elif x > 0:
print("Numero positivo")
elif x == 0:
print("Igual a 0")
else:
print("Numero negativo")
Enter a number ('' to finish): 3
Positive number
Enter a number ('' to finish):
Traceback (most recent call last):
File "", line 1, in
pcn_loop3 ()
File "C: \ 01_Mis.Documents \ 01 My Programs in Python \ My projects \ kk.py", line 3, in pcn_loop3
x = int (input ("Enter a number ('' to end):"))
ValueError: invalid literal for int () with base 10: '*'
And I can not make it come out of the loop and if I remove int to the variable x it throws me the following error:
Enter a number ('*' to finish): 3
Traceback (most recent call last):
File "", line 1, in
pcn_loop3 ()
File "C: \ 01_Mis.Documents \ 01 My Programs in Python \ My projects \ kk.py", line 6, in pcn_loop3
elif x > 0:
TypeError: unorderable types: str () > int ()
How do I get it out of the infinite cycle, without it throwing me an error ...?