CS 111 - 2/14/17 Exam 1 on Thursday 2/16 during lecture 20 multiple choice questions (3 pts each) Python questions "What is the value of z..." 2 Write Code Questions (20 pts each) 21. Write code in main() function to draw some simple diagram using a SINGLE turtle. 22. Write a function that would be called from main() - using a loop to draw a shape - pay attention to parameters Exam Topics: Python: - variables and data types Integers Floating Points Strings Boolean (true/false) - Assignment operation = - Arithmetic operations ( ) * / % + - - Relational operations > >= < <= == != - while loops (keep executing the loopBody while the is true) while : - infinite loops - sometime the condition is initially false - functions and parameters (q. 22) Q. 21 and Q. 22 - Turtle Drawings makeWorld ( ) makeTurtle ( ) forward ( ) forward ( t1, 60 ) turn ( ) penUp ( ) penDown ( ) setPenColor ( ) methods t1.setPenColor ( red ) getPenColor ( ) methods setPenWidth ( ) methods getPenWidth ( ) methods moveTo ( ) getXPos ( ) getYPos ( ) In blackboard, there is the Discussion Board to write a question for Extra Credit. You need to write your question by Wednesday Midnight x = 1 y = 3 z = 5 while ( z <= 10 ) : x = x * y y = y + 2 z = x / y x: 1 3 15 105 y: 3 5 7 9 z: 5 0 2 11 ================== thirtyFour = 1 no = 0 while ( thirtyFour <= 20 ) : no = no + thirtyFour thirtyFour = thirtyFour + 5 t: 1 6 11 16 21 n: 0 1 7 18 34 ======================= z = 1 x = 1 while (x<=5): z = (z * 5) % 2 + 2 x = x + 1 z: 1 3 3 3 3 3 x: 1 2 3 4 5 6 ========================= x = 3 z = 0 while ( x <= 7): z = z + x x = x + 2 x: 3 5 7 9 z: 0 3 8 15 ================== x = 0 z = 1 while ( x <= 5): z = z + 2 x = x + 1 x: 0 1 2 3 4 5 6 z: 1 3 5 7 9 11 13 1. ( ) 2. * / % 3. + - 5 * 3 % 6 / 2 Integer division does Truncation (drop any decimal values) Beware the difference between - integer division and floating point division 30 / 4 ==> 7 30.0 / 4.0 ==> 7.5 x = 30 / 4 * 2.0 y = 2.0 * 30 / 4 - addition of numbers and string concatenation "Hello" + "There" ===> "HelloThere" - Multiplication of numbers and string repetition "Hello" * 3 ====> "HelloHelloHello"