WHAT IS Casting
If
statements support more than ==
. They support inequality symbols as well. Remember those <, >, and = signs you used in math way back when? Well they are back again, but this time they look a bit different EXAMPLE :
myScore = input("Your score: ")
if myScore > 100000:
print("Winner!")
else:
print("Try again ")
WHAT IS INT
To change "your score" to a number, we need to add
int
in front of the input
and place the enitre input in ()
. EXAMPLE :
myScore = int(input("Your score: "))
if myScore > 100000:
print("Winner!")
else:
print("Try again 😭")
WHAT IS FLOAT
You would do the exact same thing, except using
float
for a decimal number. In the code below, I want to find pi to 3 decimal places. EXAMPLE :
myPi = float(input("What is Pi to 3dp? "))
if myPi == 3.142 :
print("Exactly!")
else:
print("Try again 😭")
Comments
Post a Comment