Introduction to Programming Python Lab 1: My First Program 8 January 2016 1 PythonLab1 lecture slides.ppt Ping Brennan

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
Advertisements

Scite Scintilla integrated text editor. Click here.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Recitation 1 Programming for Engineers in Python.
 We are going to learn about programming in general…How to think logically and problem solve. The programming language we will use is Python. This is.
CPS120: Introduction to Computer Science Compiling Your Programs Using Visual C++
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 4: Writing programs.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Hitchhiker’s Guide to CS Lee Sieger, Tim Cook, Jason Day, Zuozhi Yang.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Introduction to Programming Python Lab 5: Strings and Output 05 February PythonLab5 lecture slides.ppt Ping Brennan
Introduction to Programming
Introduction to Programming Python Lab 2: Variables 15 January PythonLab2 lecture slides.ppt Ping Brennan
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
Introduction to Programming Python Lab 6: Relational Operators and Boolean Variables 12 February PythonLab6 lecture slides.ppt Ping Brennan
Introduction to Programming Python Lab 8: Loops 26 February PythonLab8 lecture slides.ppt Ping Brennan
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introducing Python Introduction to Python.
Development Environment
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Running a Java Program using Blue Jay.
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Presentation transcript:

Introduction to Programming Python Lab 1: My First Program 8 January PythonLab1 lecture slides.ppt Ping Brennan

Module Information Lecturer: Steve J. Maybank Lecture Venue: MAL B20 Lab sessions: MAL 109 (ITS) – Main room, MAL 457 (ITS) Demonstrators: Ping Brennan, Martin O’Shea, Suneel, Ayman, Margarita, Beate Note: Lab sessions are designed to reinforce the materials covered in the lecture. Module materials: to Programming.html 2

Getting Started Create a new folder in your disk space with the name PythonLab1 Launch the Python Integrated Development Environment (IDLE) - begin with the Start icon in the lower left corner of the screen. If you are in a DCSIS lab, select the options in the order shown: Start -> All Programs -> Python 3.4 -> IDLE (Python GUI) A window with the title Python Shell should appear. This window is the Shell. 3

Getting Started (2) If you are in one of the ITS labs (MAL 109 or MAL 457), select the options in the order shown: Start -> All Programs -> Departmental Software -> Computer Science -> Python 3.4 -> IDLE (Python 3.4 GUI – 64 bit) A window with the title Python 3.4.4rc1 Shell should appear. This window is the Shell. If the window does not appear then click on Start and then in the box Search programs and files write IDLE. A list will appear. Click on IDLE(Python GUI). A window with the title Python should appear. This window is the Shell. In the Shell click on File. A drop down menu will appear. Click on New File. A window with the title Python 3.4.1:Untitled (DCSIS) or Untitled (ITS) or Python 2.7.8: Untitled (ITS) should appear. This window is the Editor. 4

Getting Started (3) In the Editor, click on File, and then in the drop down menu click on Save As…. A window showing a list of folders should appear. –To search any folder on the list, double click on the folder. –Find the folder PythonLab1 and double click on it. –In the box File name at the bottom of the window type HelloWorld.py, and then click on the button Save in the lower right corner of the window. The title of the Editor should change to show the location of the file HelloWorld.py. 5

Write and run your first program In the Editor type # My first Python program print("Hello World!") left justified and on the first line. Notice the colour coding: red for the comment, purple for the function print() and green for the data "Hello World!". 6

Write and run your first program (2) In the Editor click on Run, then on the drop down menu click on Run Module. A window will appear with the message Source Must Be Saved. Click on OK. Two things happen: 1.Your program is saved in the file HelloWorld.py and then 2.it is run to produce the text "Hello World!" in the Shell. The text in the Shell is blue to show that it is output. 7

Exercises on Syntax Errors 1.In the Editor type Print(Hello World!) on a new line and left justified. As before, click on Run Module. A window will appear. Click on OK. 2.In the Editor, replace the line Print(Hello, World!) with the line print("Hello World!) and click on Run Module. A window will appear. Click on OK. Use a web search engine to find out if others have obtained the same error message. Remove the erroneous statements from the Editor to correct them. Click on the button Compile. 8

Exercises on Print statements 1.What do the following statements print when they are executed together? print("Hello") print("World!") 2.What do the following statements print when they are executed together. Note the indentation. print("Hello") print("World!") 3.What does the following statement print? print("My lucky numbers are", 3*4+5, 5*6-1) 4.What is the error in the following statement? print(1/0) 9

Exercise on evaluation of arithmetic expressions A bank account contains $10,000 and earns interest at the rate of 5 percent per year. The interest is added to the account. (See PFE Section 1.7). After one year the bank account contains the original sum of $10,000 plus the interest, which is 5% of $10,000, namely 10,000 *(5/100). So, the account balance is *(5/100) = 10000*(1+(5/100)) = 10000*1.05 –Print out the value of 10000*1.05 using the code: print("balance after one year: ", 10000*1.05) – Find the balance of the account after two years using the code: print("balance after two years: ", 10000*1.05*1.05) –Calculate and print the number of years it takes for the account balance to be at least double the original balance. 10