Test2Review - Python Intro to IFs (2) PDF
Document Details
Uploaded by EnthusiasticFauvism4662
Tags
Summary
This document is a review of Python programming focusing on selective processing using conditional statements like if, if-else, and if-elif-else. It includes illustrative examples, exercises, and questions for practice.
Full Transcript
ICD 2O Review – Python Intro to Selective Processing 1) What function is used to get input from the keyboard? 2) What function is used to output information onto the screen? 3) What is the purpose of the /n special characters when used in output? 4) Given the followin...
ICD 2O Review – Python Intro to Selective Processing 1) What function is used to get input from the keyboard? 2) What function is used to output information onto the screen? 3) What is the purpose of the /n special characters when used in output? 4) Given the following values for x, y, and z, state the results of the following math operations and functions: x=9 y=5 z=3 Operation or Function Result x + y z - x y * z x / y Z / y x // z z // x x % y x % z y ** z -x math.sqrt(x) -x – (-z) x + y – z * z math.sqrt(z*z*x) 5) Describe each of the following data types. Give an example of each. int float string 6) The if statement has the following form: if condition: statement(s) a) What value must the condition be in order for the statements to be executed? 7) The if..else statement has the following form: if condition: statement(s) else: statement(s) a) What value must the condition be in order for the statement(s) after the else: clause to be executed? 8) The if..elif..else statement has the following form: if condition1: statement(s) elif condition2: statement(s) elif condition3: statement(s) else: statement(s) a) How many elif clauses can be contained in an if..elif..else statement? b) How many else clauses can be contained in an if..elif..else statement? 9) Given the following values for x, y, and z, state the results (true or false) of the following conditional and logical operators x=7 y=5 z=2 Operator Result x == y z > x y >= z x < y x 0 z < -4 or y > 0 not (x > 0) 10) Given the following variables and their values, determine the output of the short piece of code. x=0 y = -5 z = 10 If Statement Output if x