### Ch 7 If/else # Understand what's going on in the functions below # i.e. be careful and precise when you write code :)! # (or, in other words, don't write code like in the first two) def testyes1(input): if (input == 'Si' or 'si' or 'SI'): print('Yes :)') else: print('No :(') def testyes2(input): if (input == ('Si' or 'si' or 'SI')): print('Yes :)') else: print('No :(') def testyes3(input): if ((input == 'Si') or (input == 'si') or (input == 'SI')): print('Yes :)') else: print('No :(') ### Ch 6 Functions def foo(a, b, c): print("a: {}, b: {}, c{}".format(a,b,c)) temp = a * b result = temp + c return result # print vs return # Understand the differences between these three functions! def add1a(number): result = number + 1 return(result) def add1b(number): result = number + 1 print(result) return def add1c(number): result = number + 1 print(result) return(result) ### ### Useful for HW1: string format is super convenient for nice printing once ### you learn how to use it. def formatEx1(): item = "bicycle" itemCost = 127.123124 outputString = "The {}’s cost is S{:.2f}.".format(item, itemCost) print(outputString) outputString = f"The {item}’s cost is \${itemCost:.3f}." print(outputString) # try, e.g. formatEx2(1, 2.34567, 3.98765) def formatEx2(a, b, c): d = a + 1 e = 0 print("a: {}, b: {:.2f}, c:{:.3f}, d:{}, e:{}".format(a, b, c, d, e)) e = (23 * b) + (a / d) - 4 print("a: {}, b: {:.3f}, c:{:.1f}, d:{}, e:{}".format(a, b, c, d, e)) return e # simple example of a test function # # supposed to subtract 1 but incorrect def sub1(num): return(5) def testSub1(): testResult = sub1(6) print("Test1: sub1(6) yields {} ... {}".format(testResult, "CORRECT" if testResult == 5 else "INCORRECT")) testResult = sub1(10) print("Test2: sub1(10) yields {} ... {}".format(testResult, "CORRECT" if testResult == 9 else "INCORRECT")) def testSub1v2(): testResult = sub1(6) testResult = sub1(10)