Day 31: Conditionals And If-Statements

 

# Conditionals in Python:
# <         less than 
# >         greater than 
# <=        equal or less 
# >=        equal or greater
# ==        equal to
# !=        not equal to
# is        identical object
# is not    Not identical object


number = input("Enter a number: ")

if (int(number)%2 == 0):
    print("Number is even")
else:
    print("Number is odd")

# the conditionals 'is' and 'is not'
name_1 = "matt"
name_2 = "tim"
name_3 = name_1

if (name_1 is name_3):                  # statement is true
    print("The same object!")

if (name_1 is not name_2):              # this statement is also true
    print("Two different objects!")

score = 78

if (score > 90):
    grade = "A"
elif (score > 80):
    grade = "B"
elif (score > 70):
    grade = "C"
else:
    grade = "Failed"

print(grade)                        # C

# combining conditionals
name = "Duff"
gunsnroses = False

if (name == "axl" or
    name == "slash" or
    name == "Duff" or
    name == "steven" or
    name == "izzy"):
    gunsnroses = True
    print(gunsnroses)                           # true
else:
    gunsnroses = False
    print(gunsnroses)

# a more efficent way to do the above
gunner = False
gnr = {"Axl", "Duff", "Steven", "Izzy", "Slash"}
gunner = name in gnr

print(gunner)                                   # true

 

 

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.