Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,

Similar presentations


Presentation on theme: "CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,"— Presentation transcript:

1 CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa.edu

2 Objectives In this chapter, you will do some exercises about: – Python programming – basic control structures in Python 2

3 Multiple Choices The ____ statement instructs the computer to display information on the screen. – A. input B. output C. print D. cout A ____ is a Python data type that contains a sequence of characters – A. char B. string C. integer array D. decimal The _____ is the modulus operator. – A. mod B. \\ C. / D. % _____ are used to document a program and improve its readability – A. keywords B. symbols C. comments D. functions Each if structure consists of the word ___, the condition to be tested, a _____ and a body. – A. for … ; B. if … ; C. for … : D. if … : The ____ function converts non-integer values to integer values. – A. type() B. print() C. int() D. convert() 3

4 Multiple Choices (cont'd) A Python statement can be spread over multiple lines using the _________. – A. \n B. \ C. \\ D. // Arithmetic expressions enclosed in ___ are evaluated first. – A. parenthesis B. curly braces C. square brackets D. None of the above An object's ____ describes the information stored in the object. – A. address B. type C. function D. id 4

5 Multiple Choices (cont'd) The if/elif/else structure is a ____ structure. – A. single selection B. double selection C. repetition D. multiple selection The augmented assignment symbol *= performs _____. – A. addition B. comparison C. multiplication D. exponentiation A procedure for solving a problem is called a(n) _____. – A. algorithm B. programming language C. expression D. None of the above The keyword ____ represents an empty statement. – A. empty B. ; pass D. blank Which of the following is NOT control structure? – A. sequence B. selection C. goto D. repetition 5

6 True/False Statements The Python function get_input requests input from the user. A valid Python arithmetic expression with no parentheses is evaluated left to right. The following are invalid variable names 3g, 87, and 2h The operator != has the same meaning as <> In Python, the programmer must declare the object type before using the object in the program If parentheses are nested, the expression in the innermost pair is evaluated first 6

7 True/False Statements (cont'd) Python treats the variable names, a1 and A1, as the same variable The backslash character is called an escape sequence Pseudocode is a simple programming language The if selection structure performs an indicated action when the condition is true. The if/else selection structure is a single-selection structure. The function float converts its argument to a floating- point value. The symbol = tests for equality. 7

8 What are the Precedence of Operators in Expressions? 15*3%12+45/(9%2)**2 Product = x*y**z 8

9 Debug Errors int x=0 x=y X=15*3%12+45/(8%2)*2 print("x=%d" x) 9

10 Debug Errors (cont'd) If gender = 1; print("Woman") Else cout<< "Man"; 10

11 Debug Errors (cont'd) Counter = 0 While counter > 10 print("counter = %d", %counter) 11

12 Programming Write a Python program using nested while loop to output the following pattern to screen: * ** *** **** ***** 12


Download ppt "CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,"

Similar presentations


Ads by Google