Ho invece scoperto che questo semplice programmino si blocca:
Codice: Seleziona tutto
# ------------- sum.py ------------
a = 1
s = 0
print ('Enter Numbers to add to the sum.')
print ('Enter 0 to quit.')
while a != 0 :
print ('Current Sum:',s)
a = input('Number? ')
s = s + a
print ('Total Sum =',s)
# ------ EOF: sum.py ----------------
così:
alfabeta@ubuntu:~/Scrivania$ python3 sum.py
Enter Numbers to add to the sum.
Enter 0 to quit.
Current Sum: 0
Number? 10
Traceback (most recent call last):
File "sum.py", line 8, in <module>
s = s + a
TypeError: unsupported operand type(s) for +: 'int' and 'str'
-------------------
alfabeta@ubuntu:~/Scrivania$ python3 -V
Python 3.5.2
-------------------
Edit. Stessi costrutti su file di Py2
Codice: Seleziona tutto
Python 2.6.5
----------
$python sum.py
Enter Numbers to add to the sum.
Enter 0 to quit.
Current Sum: 0
Number? 10
Current Sum: 10
Number? -0.5
Current Sum: 9.5
Number? 0
Total Sum = 9.5

