mardi 27 octobre 2020

if x < 0: `x = 0` print('Negative changed to zero') execution

While studiyng python in https://docs.python.org/3/tutorial/controlflow.html , there was this example but I did not understand the statement of x=0, could you explain to me?:

x = int(input("Please enter an integer: "))
if x < 0:
    x = 0
    print('Negative changed to zero')  
elif x == 0:
    print('Zero')
elif x == 1:
    print('Single')
else:
    print('More')

In my experiments, if I enter the input 42. the output is More.

Aucun commentaire:

Enregistrer un commentaire