True
or False
. (The capitalization is important.)
In [ ]:
arthur = "king"
lancelot = -23
robin = 1.99
bedevere = True
In [28]:
arthur = "king"
type(arthur)
Out[28]:
In [29]:
lancelot = -23
type(lancelot)
Out[29]:
In [30]:
robin = 1.99
type(robin)
Out[30]:
In [31]:
bedevere = True
type(bedevere)
Out[31]:
In [32]:
galahad = 1
galahad = 57
galahad
Out[32]:
In [34]:
patsy = 2
patsy = "Clip clop"
type(patsy)
Out[34]:
Value can also be forced to take on a data type
But it doesn't always make sense to so
In [40]:
zoot = float(5)
zoot = 5.0
zoot
type(zoot)
zoot = "5"
type(zoot)
zoot = str(5)
zoot
type(zoot)
Out[40]:
In [49]:
arthur = "king"
galahad = "5"
print(arthur + galahad)
robin = 4
bedevere = 5.0
print(robin * bedevere)
int(20.7)
Out[49]:
In [ ]:
import sys
print(sys.maxint)
print(sys.float_info)
So far, we've been writing programs that do the same thing repeatedly. If order for a program to be more reactive, we need a way for it to make decisions. Depending on whether something is the case, it takes one action or another.
Here's the general form of an if statement
if *condition*:
statement
statement
etc.
In [51]:
cold = True
if cold:
print("Wear a coat.")
In [56]:
x = 1
y = 2
y != x
Out[56]:
In [62]:
name1 = "Mary1"
name2 = "Mary"
name1 < name2
Out[62]:
In [64]:
temperature = 10
if (temperature < 12):
print("Wear a coat.")
In [69]:
temperature = 39.5
if temperature < 40.0:
print("A little cold, isn't it?")
print("Wear a coat")
else:
print("Nice weather we're having")
print("Don't wear a coat")
print("Done the if-statement")
In [72]:
salary = 40000
years_on_the_job = 2
if salary >= 30000:
if years_on_the_job >= 2:
print("You qualify for the loan")
else:
print("You must have been on your current job for at least two years to qualify.")
else:
print("You must earn at least $30,000 per year to qualify.")
In [83]:
score = 45
if score >= 90:
print("Your grade is A")
elif score >= 80:
print("Your grade is B")
elif score >= 70:
print("Your grade is C")
else:
print ("Restart. Try again.")
print("Done with if-statement")
In [ ]: