Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: LS 30A-1 W19
Views: 254

Math

Quiz: Chain Rule and Product Rules

Please Explain

Quiz: Integration and Linear Approximation

Please explain the pink area in the below area can be calculated as follows:







Programming

IF AND ELSE


Make Decision!

Else is "what to do" if all if statements return False




Different Priority

Not all decisions have the same priority!

Example: Buying Dinner

You will not check your walet before you are hungry!!! If hungry => If have money => Buy Dinner!




BTW, the graph I used are called "Flow Chart", which is common in programming Basically, diamonds mean decisions, rectangles means actions!


Python Syntax

var1 = 10 if var1 == 8: print("var1 is 8") elif var1 == 9: print("var1 is 9 ") elif var1 == 10: print("var1 is 10") else: print("var1 is not 8,9,10")
var1 is 10

What if var1 = 11?





Relational operator

  • a<b: Is a less than b?

  • a>b: Is a larger than b?

  • a == b: Is a equal to b?

  • a>=b: Is a larger or equal to b?

  • a<=b: Is a less or equal to b?

a=1 b=2 c=2 a>b a==c b>=c b>c
False False True False

Comapre Strings

s1 = 'string1' s2 = 'string2' s1 == s2 s1[0:6]==s2[0:6]
False True

While Loop



  • We have learned for loop when we need to do repeated task.

  • What if we don't know how many loops we need?

Wait? Then when should we end?


Use if/else statement

while(decision!): things you want to do in the loop!

Example: Print all integers square is less than 100
startNum=0 while(startNum^2<100): print(startNum) startNum+=1
0 1 2 3 4 5 6 7 8 9

Exercise 15 is quite difficult

Goal: Comapring 2 list with same length! example:

from haoSecretFun import compareList #of course I will not let you see my code!!!! #Hint: you may need 2 for loops! list1 = ["cat","dog","rabbit","pig"] list2 = ["horse","cat","dog","pig"] table(compareList(list1,list2))
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute flags=compile_flags) in namespace, locals File "", line 1, in <module> ImportError: cannot import name compareList