ENGR 102 Engineering Lab I - Computation
|
|
- Gerard Simon
- 5 years ago
- Views:
Transcription
1 ENGR 102 Engineering Lab I - Computation Week 03: Data Types and Console Input / Output Introduction to Types As we have already seen, 1 computers store numbers in a binary sequence of bits. The organization and interpretation of those bits depends on the type of the data stored. We have seen that floating point numbers store the sign of the number, the value of the exponent, and the value of the mantissa, or fractional part of the number (refer to Figure 1). Other data types may have a different number of bits, and each bit could have a different interpretation. For the 32-bit, single-precision floating-point number in Figure 1, the second bit from the left tells the computer whether or not to include 2 8 in the sum of numbers needed to evaluate the exponent of the float. 1 These notes are based closely on a PowerPoint presentation prepared by Dr. John Keyser for the Pilot Course version of ENGR bits Sign Exponent (8 bits) Mantissa, or Fraction (23 bits) In this lecture, we will focus on the fundamental data types of integers, floating-point numbers, Booleans, 2 and strings. 3 As we learned in the notes for Week 2, Python is dynamically typed, and Python will make choices about data types when you create variables and when you use them. Thus, we need to know what data types our variables are, what the standard operators will do with different data types, and what data types the output of an operation will be. Without this knowledge, calculation errors can easily enter our programs. Figure 1: Schematic of the 32 bits used to store a single-precision, floating point variable. 2 A Boolean variable represents True and False. Booleans only have these two values. 3 As string is a list of characters strung together. We create strings using different combinations of quotation marks. Variables as Objects The most fundamental data type in Python is an object. Every variable and data type is stored as an object. Here, we use the word object with the computer science meaning, as in the phrase objectoriented programming. An object is simply a container that holds
2 2 engr data 4 and methods that can act on that data. 5 We can use Python without realizing that its variables are objects, but we can access much more of the capability in Python if we use this knowledge to access the attributes and methods of Python objects. At this point, we will learn two key aspects of objects: the concepts of initialization and attributes and methods. When we initialize an object, we create it and store the necessary data associated with the object. You used the assignment operator = to create different variables in the previous two weeks of this course. If you write: 4 The object x holds the value 7.15 if we create it with the command x = Methods are functions that can analyze and manipulate the data stored in the object. For example, floating-point variables have the method.is_integer(), which returns a True/False value as to whether or not the data stored in the variable is an integer. x = 7.15 you create an object x that stores the floating-point value If you use x in an expression, 6 the x-object returns the value stored in the object. In this case, x will return 7.15 until a new value is stored in x. When Python created your x variable, it also created some additional variables stored inside x that we call attributes. These should normally be regular Python variables associated with the data stored in the object. As an example, floating point variables can be real or imaginary. It makes sense that floating-point objects have attributes that store the real and imaginary parts of the float. Continuing our example, we access the attributes of an object using the.-operator: 6 You could use a mathematical expression like (7. * x) or you may use x in a print statement like print(x). print(x.real) print(x.imag) will print the real (7.15) and imaginary (0.0) parts of the data stored in our variable x. Attributes are simply additional variables stored inside our object and accessible through the.-operator. In addition to the attributes stored in objects, objects also have internal, built-in functions that can do operations with the data stored in the object. These are also accessed using the.-operator. As an example, floating point variables can express themselves as fractions containing only integer values. The method that returns the numerator and denominator of this fraction for a floating-point variable in Python is called as_integer_ratio(). Because methods are functions (and not attributes, which are stored like variables), you always use (), and possibly additional input data, with methods. Here, we could write: x.as_integer_ratio() and when this line executes, we may see the following output: 7 ( , ) Using the PyCharm IDE, if you type your variable name and then a., PyCharm will show you a list of all available methods for a given object and some ideas about how to use them. In the remainder of this lecture, we will learn about the fundamental numerical, logical (Boolean), and string data types. We will also learn how to use some of the powerful methods associated with string objects. 7 Try dividing these numbers to verify whether or not this worked and whether or not it produces the output you expect. Why do you think these numbers are so large? Why might this function not return 715 and 100?
3 engr 102 engineering lab i - computation 3 Number Data Types: int() and float() Our two number-based data types are integers and floats. We create an integer by typing any whole number without a decimal point. 8 8 All of these are integers: 5, 12, -1, We can also convert other data types to integers using int(). The -1024, 1139, etc. int() function works on real numbers and on strings that contain only whole numbers. For example, if we write: age = 12 x = int(age) we first store the value 12 as a string in the variable age, and we then store the value of age in the variable x as an integer. 9 We create a floating-point number by including a decimal point with the number during assignment. 10 Like integers, we can create floats from other data types using the float() function. float() also works on integers and strings, and in this case, the string can define a floating-point number using a decimal. 11 Because Python is dynamically typed, variables can also change their type automatically when they are used. This is powerful and important and can easily be the source of programming 9 If we had entered age = 12., the command int(age) would give an error since the string 12. contains a decimal point, which is not part of an integer. 10 All of these are floats: 5., 12.0, , 6e-12, 7.0e5, etc. Note that the decimal point is hidden in the number 6e-12 as this is scientific notation for What do you think float( 12 ) will return? Try it in Python. errors! Many of our mathematical operators 12 are defined for multi- 12 The standard list of operators is: +, -, *, /, **, //, and %. ple data types, and the type returned after the math operation may depend on the data types of the variables involved. If we add two integers, Python returns an integer; if we add two floats, Python returns a float. What if we add an integer to a float? Python makes a decision, and not all versions of Python may give the same result. For example, if we divide an integer by an integer such that the result has a remainder, Python 3.6 will return a float, but Python 2.7 will return an integer. In other words, if we type: x = 7 / 3 the result is in Python 3.6 and 2 in Python 2.7 since 3 and 7 are both integers and Python makes a decision about what datatype it thinks you likely want for output. Hence, it is very important to know what data type will be returned by mathematical operations. In general, you get what you expect, but not always. Booleans Boolean variables store the values True and False. These two capitalized words are built-in keywords in Python. When used in an operation, True values are assumed to have the value 1, and False values have the value 0. When you create a Boolean variable from an integer or float, though, the numeric value 0 is interpreted as False and any other value is interpreted as True.
4 4 engr The built-in function to create Boolean variables from numbers is bool(). The bool() function can work on floats, integers, and strings. Note that all strings are interpreted as true except for the empty string 13 Hence, bool( 0 ) is True. 14 Strings and String Operations As stated above, we create strings using different combinations of quotation marks. We can use single-quote, double-quotes ", multiple single or double quotes: str1 = strings are fun str2 = ""you can do a lot with a string"" 13 i.e., two single quotation marks without any space between them in Python, this creates an empty string, which is like the number zero: nothing. 14 All of these evaluate to False: 0, 0.0, bool(0), bool(0.), and bool( ); all of these evaluate to True: 1, 1., 5., , bool( 0 ), bool( False ), etc. Try these in an interactive Python window (ipython) to get familiar with Boolean variables. You can also create strings using the str() function for example, if you want to convert a float to a string. Some of the mathematical operators are also defined for string. For example, the plus sign + means concatenation for strings: it splices two strings together. As a result: my house + is green will produce: my houseis green. To get a space between house and green, we need a space in one of the strings: my house + is green will produce: 12. Notice that Python does not guess that you wanted to add two integers and convert your strings to integers. Since + is defined as concatenation for strings, when you add two strings, you get the two strings spliced together. The multiplication operator * is also defined for strings and will repeat the string the integer number of times implied by the multiplication. 15 We can use this new understanding of string behavior and type conversions to produce much more readable results from our programs using print(). Consider the case we would like our program to output: 15 Python expects an integer in the string multiplication and will not convert a float to an integer; hence: 3 * you will produce: youyouyou. 3. * you will throw an error. A sphere of radius 12.0 cm contains cubic centimeters We can assemble this string as follows (this is just one of many ways): r = 12. vol = 4. / 3. * pi * r**3 out_text = A sphere of radius + str(r) + cm contains + \ str(vol) + cubic centimeters print(out_text) This gives us most of what we want. When I executed this on my machine, I found: A sphere of radius 12.0 cm contains cubic centimeters
5 engr 102 engineering lab i - computation 5 We have more decimal points in the volume term than we would like, and we will learn to deal with this later. 16 But, for now, this is better than multiple print() statements. 16 See the examples shown during the lab time this week. We can also use some of the methods available in string objects to help format our strings. Three such methods are ljust(n), rjust(n), and center(n). Each of these will left-justify, right-justify or center a string within a region that is n characters long. Remember, we access methods of objects using the.-operator, which is typed immediately following the name of the object on which we want the method to act: text = str( 2.34 ) text.rjust(8) The second line above will append 4 spaces on the left of the string stored in text. Hence, the value stored in text will now be 2.34 where I have used an underscore to show each of the four leading spaces that were inserted by.rjust(). We will practice more of this in the lecture and lab time this week. Input Instead of writing all of the input data directly in our programs, it would be nice if we could receive input from the user during program operation. One way to do this in Python is using the input() function. If we type input() by itself, the program will stop and wait for the user to type characters until the <enter> key is typed. The function will then return all of the characters typed by the user except for the <enter> key. Usually, we would use the input() function in an assignment operation: in_text = input() Notice that input() returns the string typed by the user, even if the user only typed numbers. If you want the input to be interpreted as a number, you must convert the string to a number: 17 r = float(input()) n = int(input()) 17 Try running these commands in Python If you execute this program, you will notice that no messages are written to the screen telling the user what to enter. You can write a message using either print() before the input() command or by sending the text as input to the input() function: print( Enter the radius in cm: ) r = float(input()) n = int(input( How many terms do you want to calculate? ))
6 6 engr The only difference is that the input() function does not start a new line before the user types their data; whereas, a new line is created before the input command using print. The console output of this code might have looked like this: Enter the radius in cm: 3.54 How many terms do you want to calculate? 7 Process finished with exit code 0 Later, we will learn to get input from files. In the Lab this week, we will practice using Python types to write short programs, format strings, and to get data from the user during execution of these programs.
Lecture 3. Input, Output and Data Types
Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and
More informationExpressions and Variables
Expressions and Variables Expressions print(expression) An expression is evaluated to give a value. For example: 2 + 9-6 Evaluates to: 5 Data Types Integers 1, 2, 3, 42, 100, -5 Floating points 2.5, 7.0,
More informationENGR (Socolofsky) Week 02 Python scripts
ENGR 102-213 (Socolofsky) Week 02 Python scripts Listing for script.py 1 # data_types.py 2 # 3 # Lecture examples of using various Python data types and string formatting 4 # 5 # ENGR 102-213 6 # Scott
More informationENGR 102 Engineering Lab I - Computation
ENGR 102 Engineering Lab I - Computation Week 07: Arrays and Lists of Data Introduction to Arrays In last week s lecture, 1 we were introduced to the mathematical concept of an array through the equation
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationComputer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and
More informationLecture 1. Types, Expressions, & Variables
Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping
More informationCSC 120 Computer Science for the Sciences. Week 1 Lecture 2. UofT St. George January 11, 2016
CSC 120 Computer Science for the Sciences Week 1 Lecture 2 UofT St. George January 11, 2016 Introduction to Python & Foundations of computer Programming Variables, DataTypes, Arithmetic Expressions Functions
More informationCOMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.
COMP1730/COMP6730 Programming for Scientists Data: Values, types and expressions. Lecture outline * Data and data types. * Expressions: computing values. * Variables: remembering values. What is data?
More informationEx: If you use a program to record sales, you will want to remember data:
Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Note about posted slides The slides we post will sometimes contain additional slides/content, beyond what was presented in any one lecture. We do this so the
More informationCS 115 Lecture 4. More Python; testing software. Neil Moore
CS 115 Lecture 4 More Python; testing software Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 8 September 2015 Syntax: Statements A statement
More informationBasic data types. Building blocks of computation
Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values
More informationCSEN 102 Introduction to Computer Science
CSEN 102 Introduction to Computer Science Lecture 2: Python and Sequential Algorithms Prof. Dr. Slim Abdennadher Dr. Aysha Alsafty, slim.abdennadher@guc.edu.eg, aysha.alsafty@guc.edu.eg German University
More informationIntroduction to: Computers & Programming: Review prior to 1 st Midterm
Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in
More informationIntroduction to programming with Python
Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:
Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationDatatypes, Variables, and Operations
Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationCS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore
CS 115 Data Types and Arithmetic; Testing Taken from notes by Dr. Neil Moore Statements A statement is the smallest unit of code that can be executed on its own. So far we ve seen simple statements: Assignment:
More informationCS112 Lecture: Primitive Types, Operators, Strings
CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive
More informationPython Input, output and variables
Today s lecture Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016! What is Python?! Displaying text on screen using print()! Variables! Numbers and basic arithmetic! Getting input from
More informationVariable and Data Type I
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store
More informationPython Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016
Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016 Today s lecture u What is Python? u Displaying text on screen using print() u Variables u Numbers and basic arithmetic u Getting input
More informationProgramming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur
Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,
More informationChapter 2 Getting Started with Python
Chapter 2 Getting Started with Python Introduction Python Programming language was developed by Guido Van Rossum in February 1991. It is based on or influenced with two programming languages: 1. ABC language,
More informationChapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers
Chapter 03: Computer Arithmetic Lesson 09: Arithmetic using floating point numbers Objective To understand arithmetic operations in case of floating point numbers 2 Multiplication of Floating Point Numbers
More informationREVIEW. The C++ Programming Language. CS 151 Review #2
REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,
More informationFundamentals of C Programming
Introduction, Constants, variables, keywords, Comments, I/O Functions, Data types, Compilation & Execution Tejalal Choudhary tejalal.choudhary@gmail.com, tejalal.choudhary@sdbct.ac.in Department of Computer
More informationLecture 1. Course Overview, Python Basics
Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures and Labs are at fire-code capacity We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are
More informationIntroduction to Scientific Computing Lecture 1
Introduction to Scientific Computing Lecture 1 Professor Hanno Rein Last updated: September 10, 2017 1 Number Representations In this lecture, we will cover two concept that are important to understand
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationIntroduction to Computer Programming in Python Dr. William C. Bulko. Data Types
Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have
More informationPython The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT
Python The way of a program Srinidhi H Asst Professor Dept of CSE, MSRIT 1 Problem Solving Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution
More informationIntroduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1
Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables
More informationVARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals
VARIABLES WHAT IS A VARIABLE? A variable is a storage location in the computer s memory, used for holding information while the program is running. The information that is stored in a variable may change,
More informationLecture 1. Course Overview, Python Basics
Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures are at fire-code capacity. We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are allowed
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationExercise: Using Numbers
Exercise: Using Numbers Problem: You are a spy going into an evil party to find the super-secret code phrase (made up of letters and spaces), which you will immediately send via text message to your team
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationUniversity of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.
University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.
More informationLecture Numbers. Richard E Sarkis CSC 161: The Art of Programming
Lecture Numbers Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To understand the concept of data types To be familiar with the basic numeric data types in Python To be able
More information3 The Building Blocks: Data Types, Literals, and Variables
chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating
More informationProfessor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators
1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with
More informationENGR 101 Engineering Design Workshop
ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as
More informationIntroduction to Programming, Aug-Dec 2008
Introduction to Programming, Aug-Dec 2008 Lecture 1, Monday 4 Aug 2008 Administrative matters Resource material Textbooks and other resource material for the course: The Craft of Functional Programming
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationCEN 414 Java Programming
CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea
More informationFloating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.
Floating-point Arithmetic Reading: pp. 312-328 Floating-Point Representation Non-scientific floating point numbers: A non-integer can be represented as: 2 4 2 3 2 2 2 1 2 0.2-1 2-2 2-3 2-4 where you sum
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationCSCE 110 Programming I
CSCE 110 Programming I Basics of Python (Part 1): Variables, Expressions, and Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2013 Tiffani
More informationDaMPL. Language Reference Manual. Henrique Grando
DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4
More informationIntroduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 LNGG 1003 Khaleel I. Shaheen Introduction to Computers Laboratory Manual Experiment
More informationCSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output
CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2011 Python Python was developed
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationIntroduction to Python and programming. Ruth Anderson UW CSE 160 Winter 2017
Introduction to Python and programming Ruth Anderson UW CSE 160 Winter 2017 1 1. Python is a calculator 2. A variable is a container 3. Different types cannot be compared 4. A program is a recipe 2 0.
More informationENGR 102 Engineering Lab I - Computation
ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;
More informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types
More informationPYTHON. Values and Variables
December 13 2017 Naveen Sagayaselvaraj PYTHON Values and Variables Overview Integer Values Variables and Assignment Identifiers Floating-point Types User Input The eval Function Controlling the print Function
More informationCOSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)
COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you
More informationMath Day 2 Programming: How to make computers do math for you
Math Day 2 Programming: How to make computers do math for you Matt Coles February 10, 2015 1 Intro to Python (15min) Python is an example of a programming language. There are many programming languages.
More informationProgramming with Python
Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationTopic 2: Introduction to Programming
Topic 2: Introduction to Programming 1 Textbook Strongly Recommended Exercises The Python Workbook: 12, 13, 23, and 28 Recommended Exercises The Python Workbook: 5, 7, 15, 21, 22 and 31 Recommended Reading
More informationChapter 2 Working with Data Types and Operators
JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationAt full speed with Python
At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3
More informationVariable and Data Type I
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved
More informationBuilt-in Types of Data
Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),
More informationProgramming Using C Homework 4
Programming Using C Homewk 4 1. In Homewk 3 you computed the histogram of an array, in which each entry represents one value of the array. We can generalize the histogram so that each entry, called a bin,
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions
More informationIntroduction to Computation for the Humanities and Social Sciences. CS 3 Chris Tanner
Introduction to Computation for the Humanities and Social Sciences CS 3 Chris Tanner Lecture 4 Python: Variables, Operators, and Casting Lecture 4 [People] need to learn code, man I m sick with the Python.
More informationIntroduction to the C++ Programming Language
LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming
More information4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning
4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.
More informationIntroduction to TURING
Introduction to TURING Comments Some code is difficult to understand, even if you understand the language it is written in. To that end, the designers of programming languages have allowed us to comment
More informationNumber Systems. Both numbers are positive
Number Systems Range of Numbers and Overflow When arithmetic operation such as Addition, Subtraction, Multiplication and Division are performed on numbers the results generated may exceed the range of
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationReserved Words and Identifiers
1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the
More informationFundamentals: Expressions and Assignment
Fundamentals: Expressions and Assignment A typical Python program is made up of one or more statements, which are executed, or run, by a Python console (also known as a shell) for their side effects e.g,
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationCSE 20. Lecture 4: Number System and Boolean Function. CSE 20: Lecture2
CSE 20 Lecture 4: Number System and Boolean Function Next Weeks Next week we will do Unit:NT, Section 1. There will be an assignment set posted today. It is just for practice. Boolean Functions and Number
More informationENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python
ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python ENGG1811 UNSW, CRICOS Provider No: 00098G W4 Computers have changed engineering http://www.noendexport.com/en/contents/48/410.html
More informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical
More informationCS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007
CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted
More informationCHAPTER 3: CORE PROGRAMMING ELEMENTS
Variables CHAPTER 3: CORE PROGRAMMING ELEMENTS Introduction to Computer Science Using Ruby A variable is a single datum or an accumulation of data attached to a name The datum is (or data are) stored in
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationGetting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013
CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?
More informationReview for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure
Computer Systems Computer System Computer Structure C++ Environment Imperative vs. object-oriented programming in C++ Input / Output Primitive data types Software Banking System Compiler Music Player Text
More informationPython Working with files. May 4, 2017
Python Working with files May 4, 2017 So far, everything we have done in Python was using in-memory operations. After closing the Python interpreter or after the script was done, all our input and output
More informationCOMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th
COMS 1003 Fall 2005 Introduction to Computer Programming in C Bits, Boolean Logic & Discrete Math September 13 th Hello World! Logistics See the website: http://www.cs.columbia.edu/~locasto/ Course Web
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.
More information7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING
KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve
More informationNumber Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example
Appendix F Number Systems Binary Numbers Decimal notation represents numbers as powers of 10, for example 1729 1 103 7 102 2 101 9 100 decimal = + + + There is no particular reason for the choice of 10,
More information