C# Control Statements

C# Control Statements

CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) Exercises Xiang Lian The University of Texas Pan American Edinburg, TX 78539 [email protected] 1 Objectives In this chapter, you will do some exercises about: Python programming basic control structures in Python

2 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 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 Multiple Choices (cont'd) The if/elif/else structure is a ____ structure. A. single selection multiple selection B. double selection

C. repetition D. 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 None of the above D. 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 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 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 floatingpoint value. The symbol = tests for equality.

7 What are the Precedence of Operators in Expressions? 15*3%12+45/(9%2)**2 Product = x*y**z 8 Debug Errors int x=0 x=y X=15*3%12+45/(8%2)*2 print("x=%d" x)

9 Debug Errors (cont'd) If gender = 1; print("Woman") Else cout<< "Man"; 10 Debug Errors (cont'd) Counter = 0 While counter > 10 print("counter = %d", %counter)

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

Recently Viewed Presentations

  • DESCRIPCION ES ACT 1: ESCUCHAR Listen to the

    DESCRIPCION ES ACT 1: ESCUCHAR Listen to the

    TransformaciÓn extrema. You have developed a new product/ program that results in "UNA TRANSFORMACIÓN EXTREMA" Choose 2 pictures, one that represents the " ANTES " and the other that illustrates the "
  • Things to know for tomorrows quiz  Static electricity

    Things to know for tomorrows quiz Static electricity

    Bohr-Rutherford Diagram Rules. The atomic number of an element shows you how many protons and electrons there are (# of protons = # of electrons). ... Notation for Boron-10 and Boron-11. Mass number. Atomic number. Notation for Boron-10 and Boron-11....
  • The Shoulder - Sussex MSK Partnership

    The Shoulder - Sussex MSK Partnership

    Rotator Cuff Tears-Management. Pain relief (NSAID's) Activity modification and relative rest. Ice therapy. Refer to physiotherapy via MSK service. For suspected acute traumatic rotator cuff tears, especially in the younger patient, need urgent referral to MSK service when limited improvement...
  • Chapter 1: The Foundations: Logic and Proofs

    Chapter 1: The Foundations: Logic and Proofs

    Most instructions consist of opcodes only. Some special instructions have one or two operand. LOAD. and . STORE. instructions require a single memory address operand. PUSH. and . POP. operations involve only the stack's top element. Push X: place the...
  • Fundamentals of Forensic DNA Typing

    Fundamentals of Forensic DNA Typing

    Chapter 12 DNA Databases Fundamentals of Forensic DNA Typing Slides prepared by John M. Butler June 2009 Chapter 12 - DNA Databases Chapter Summary DNA databases in many cases enable successful conclusion to forensic cases without suspects and connection of...
  • Apresentação do PowerPoint

    Apresentação do PowerPoint

    gestÃo de programas e projetos esportivos. eduardo de lima melo. educaÇÃo fÍsica - ufc. mestre polÍticas pÚblicas - uece. doutorando (polÍticas de esporte) - unb
  • The Epic Form: Epic Conventions &amp; Elements Literary Term Glossary

    The Epic Form: Epic Conventions & Elements Literary Term Glossary

    The Epic Form: Epic Conventions & ElementsLiterary Term Glossary. Term. Definition. Example. Epic Hero. A larger than life figure, typically of noble or semi-divine birth who pits his courage, skill and virtue against evil forces. Achilles. Beowulf. Tragic Flaw.
  • Chapter 5: Hair - Humble Independent School District

    Chapter 5: Hair - Humble Independent School District

    The Medulla. The medulla is the hair core that is not always visible. The medulla comes in different types and patterns. Types: Intermittent or interrupted. Fragmented. Continuous. Stacked. Absent—not present. Kendall/Hunt Publishing Company.