vendredi 9 septembre 2016

why are both if and else statements printed

Code:

bob = 15
jim = 50
john = 46
jam = 17

age = int(input("Input your age"))
if age == 15:
    print ("Hello Bob")

if age == 46:
    print ("Hello Jon")

if age == 50:
    print ("Hello Jim")

if age == 17:
    print ("Hello Jam")

else:
    print ("You are not part of the family")

Sample interactions:

Input your age: 15
Hello Bob
You are not part of the family

Both the else and if statements print despite the fact the if statement is already being used. If I indent the else statement I get a syntax error but it does not specify where.

Aucun commentaire:

Enregistrer un commentaire