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

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C Programming
CMT Programming Software Applications
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Chapter 2 Data Types, Declarations, and Displays
Introduction to C Programming
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to C++ Programming
COMPUTER SCIENCE I C++ INTRODUCTION
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.
The University of Texas – Pan American
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Input, Output, and Processing
Chapter 2: Using Data.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Week 1 Algorithmization and Programming Languages.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Fundamental Programming: Fundamental Programming Introduction to C++
CSCI/CMPE 4341 Topic: Programming in Python Review: Final Exam Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
Chapter 2 Variables.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
CSCI/CMPE 4341 Topic: Programming in Python Chapter 4: Control Structures (Part 2) Xiang Lian The University of Texas – Pan American Edinburg, TX
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Topics Designing a Program Input, Processing, and Output
Chapter 2 Introduction to C++ Programming
Revision Lecture
The Selection Structure
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
The University of Texas – Pan American
The University of Texas – Pan American
Introduction to C++ Programming
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
CS111 Computer Programming
The University of Texas – Pan American
The University of Texas – Pan American
3 Control Statements:.
The University of Texas – Pan American
The University of Texas – Pan American
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
The University of Texas – Pan American
Presentation transcript:

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

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 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

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 floating- point 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