# last time we did plot of function
plot(sin(x),(-6,6))
# parametric plot
t=var('t') # want t to be a symbolic variable
parametric_plot([cos(t),sin(t)], (t,0,2*pi))
# programming
a=7 # sets a equal to 7, example of assignment
7=a # doesn't make sense, because 7 cannot be changed
3 = 7 # doesn't make sense
3 == 7 # test for equality
# 3==7 is an expression
# a=7 is a statement
3==3
(11*7+34) == 101
# control statements if, for
if (11*7+34) == 101:
print("they are equal")
if 11+4 == 15:
print("they're equal")
print(11+4)
print("outside of block now")
if 11+4 == 16:
print("they're equal")
print(11+4)
print("outside of block now")
a = 7
if a==7:
print("you won the lottery")
a = 8
if a==7:
print("you won the lottery")
a = 8
if a==7:
print("you won the lottery")
else:
print("you did not win the lottery")
# other types of comparisons, beyond ==
3 < 7
3 > 7
3 < 3
3 <= 3
a = 8
if not a == 7:
print("you did not win lottery")
a!=7 # equivalent to not a==7
# can combine True/False expressions with and
# you win the lottery if your a,b are both right
a = 10
b = 19
if (a==11) and (b==19):
print("you won the lottery")
if (a==11) or (b==19):
print("you got one number right")
# variable names and keywords
this_is_a_variable = 88
a1 = 89
1a = 89 # not allowed, can't start variable name with number
and = 1
# cannot use reserved keywords (if, and, print, else, True, False)
# for variable names
# order of operations PEMDAS
3 + 2*7
(3+2)*7
3 + (2*7)
2==2 and (3==4 or 5==5)
True and (False or True)
True and (True)
(2==2 and 3==4) or 5==5
(True and False) or True
False or True
# in the above, moving parentheses didn't change answer
# but sometimes
not (1==1 or 3==3)
(not 1==1) or 3==3
# for statements (loops)
for i in range(10):
print(i)
range(10) # shorthand for list starting at 0, going through 10-1
for i in [1,3,4]:
print(i)
for i in range(5):
print("hello")
# print out all numbers between 0 and 100
# whose square is less than 56
# shows power of combining loops with conditional statements
for i in range(101):
# test whether i has square less than 56
if i^2 < 56:
print(i)