Exploring Python Basics

Similar documents
Exploring Python Basics

CS1110 Lab 1 (Jan 27-28, 2015)

Practice with Functions

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

More on Conditionals: if-elif-else, Boolean Expressions

Laboratory Exercise #0

CSCI 121: Anatomy of a Python Script

ASCII Art. Introduction: Python

Lab 1: Setup 12:00 PM, Sep 10, 2017

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

CS 1301 Exam 1 Spring 2014

Using IDLE for

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

What you get When you install Python for your computer, you get a number of features:

Barchard Introduction to SPSS Marks

Your Name: Section: INTRODUCTION TO STATISTICAL REASONING Computer Lab #4 Scatterplots and Regression

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Barchard Introduction to SPSS Marks

Project 1 Balanced binary

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

CMSC 201 Fall 2018 Lab 04 While Loops

CS 1110, LAB 1: PYTHON EXPRESSIONS.

BCH339N Systems Biology/Bioinformatics Spring 2018 Marcotte A Python programming primer

CS 1301 Exam 1 Spring 2014

CMSC 201 Spring 2017 Lab 01 Hello World

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

1) Log on to the computer using your PU net ID and password.

Writing and Running Programs

Part III Appendices 165

LAB #5 Intro to Linux and Python on ENGR

CS 190C: Introduction to Computational Thinking

Week 1: Introduction to R, part 1

Python lab session 1

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

Blackboard for Faculty: Grade Center (631) In this document:

CSI Lab 02. Tuesday, January 21st

Name Feb. 14, Closed Book/Closed Notes No electronic devices of any kind! 3. Do not look at anyone else s exam or let anyone else look at yours!

A computer program is a set of instructions that causes a computer to perform some kind of action. It isn t the physical parts of a computer like the

Moodle 3.1 Backup and Restore

The >>> is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

Welcome to Moodle! How To Moodle

Programming Project 1

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

appstats6.notebook September 27, 2016

Midterm 1 1 /8 2 /9 3 /9 4 /12 5 /10. Faculty of Computer Science. Term: Fall 2018 (Sep4-Dec4) Student ID Information. Grade Table Question Score

APPM 2460 Matlab Basics

Using Accommodate. Information for SAS Students at UofG

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Using Accommodate. Information for SAS Students at UofG

Chapter 3 Analyzing Normal Quantitative Data

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CMSC 201 Spring 2018 Lab 01 Hello World

Getting Started with Python and the PyCharm IDE

Python Input, output and variables

Science One CS : Getting Started

All Native Inc Customer Web Portal

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

PBWORKS - Student User Guide

Lecture 7. Processing Development Environment (or PDE)

You Need an Interpreter! Comp Spring /28/08 L10 - An Interpreter

Introduction to 3D computer modeling

Submitting Assignments

Welcome to the Using Objects lab!

Introduction to Wimba

CS10001: Computer Literacy Lab Assignment #4

PYOTE installation (Windows) 20 October 2017

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

CMSC 201 Spring 2016 Lab 04 For Loops

1. The Normal Distribution, continued

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Welcome to the Using Objects lab!

Introduction to Programming

COS 116 The Computational Universe Laboratory 8: Digital Logic II

CSC105, Introduction to Computer Science I. Introduction. Perl Directions NOTE : It is also a good idea to

CS240: Programming in C

CSCE 110: Programming I

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

CS 051 Homework Laboratory #2

Boardmaker 5.0 (Macintosh) Creating a Story Response Board. Introduction. Case Study. Learning Objectives

Tips from the experts: How to waste a lot of time on this assignment

Lab 19: Excel Formatting, Using Conditional Formatting and Sorting Records

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

Intermediate Programming, Spring Misha Kazhdan

SIS offline. Getting Started

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Laboratory 1: Eclipse and Karel the Robot

15-110: Principles of Computing, Spring 2018

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Unit 7: Algorithms and Python CS 101, Fall 2018

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

MS Word Basics. Groups within Tabs

CS 2316 Individual Homework 1 Python Practice Due: Wednesday, January 20 th, before 11:55 PM Out of 100 points

UPDATING SOCRATES Version Build May 2018

Transcription:

CptS 111 Lab #1 Exploring Python Basics Learning Objectives: - Use the IDLE Shell window to run Python interactively - Use the IDLE Editor window to write a Python program (script) - Run Python programs in the Shell window - Write programs that make use of concepts from zybooks and save them to a directory/folder Lab Procedure: Each lab consists of tasks that must be done in order. When instructed to do so, you must demonstrate to your TA that you have completed a task or you won t get credit for it. Credit is binary: you either get credit or you don t. The same procedure will be followed for all labs. 1 Your TA will help you with the tasks as needed, particularly during this first lab. You are also free to ask for help from your classmates and to offer it as well. The initial tasks indicated by 0 s don t count for credit because they re housekeeping tasks. Task 0: If you haven t done so already, open an account on Piazza (http://piazza.com). The Piazza forum will become very useful to you when you become stuck on programming assignments! Your instructors (I m including TAs as instructors) will also use it to communicate with you, e.g., letting you know whether they have to cancel their office hours. Task 00: Be sure that you have a correct version of Python on your laptop (3.4, 3.5, or 3.6). If you don t have a correct version, download it fromhttp://python.org/download. If you run into problems, ask for help. (Note to Mac users: You ll also need to install ActiveTcl from http://www.activestate.com/activetcl/downloads.) Task 000: Start the IDLE application. IDLE is an Integrated Development Environment (IDE) that allows you to run the Python interpreter. It has an interactive window called the Shell window where you can enter commands and run programs, and it has an Editor window that allows you to write and save programs (code/scripts). The IDLE IDE is simple compared to other IDEs, but it will still provide some help with commands as you will discover. Windows: To start IDLE, click the Start button in the lower left corner of the screen. If you don t see Python in the menu that appears, click on All Programs. Eventually you ll see a list of applications. Click on Python 3.x and then on IDLE (Python GUI). This should bring up a window labeled Tk Python Shell. The interactive Python prompt (>>>) indicates that you can enter Python commands because you re in the IDLE Shell window. 1 TAs can award partial credit if they think it s justified. 1

Mac OS X: In a Finder window look for a directory called Python 3.x in the Applications folder. Click on the directory, and then double click on IDLE. This will open up the IDLE Shell window where you can enter Python commands. Task 1: Using the IDLE Shell Window. IDLE allows you to have one Shell window and multiple Editor windows (we ll discuss Editor windows in the next Task). You use the Shell window to run Python interactively and to run programs that you ve created in an Editor window (you can also run Python programs, also called scripts, at the command line, but we won t cover this in CptS 111). Type the following commands into the Shell window: 1. help(print): As its name implies the help() function will provide help with certain Python constructs.. cat = : Declare the variablecat and assign it a value of. 3. type(cat): Returns the data type of the value stored in variablecat. What is it? 4. cat = dog : Reassign the stringdog to the variablecat. 5. type(cat): Now what iscat s type? 6. # This is a comment.: Comment lines start with an octothorpe. 7. type(cat) # No comment.: Comment lines can be placed next to a command, but they should be used carefully so comments don t get missed. Figure out how to get the following output: >>> Hello-O-World, and (another blank line) Goodbye-O-World! >>> Note that the interactive prompt signs and the blank line text are not to be reproduced but are included to let you know you re supposed to have blank lines in some places. Remember that you can usehelp(print) if you need help in figuring out how to print a blank line. Task : Using the IDLE Editor Window and Saving Files In this task you will use the editing capability of IDLE to edit a file and then save it to a directory. First open IDLE. Next click on thefile menu and then highlight and click onnew Window, or, alternatively, type Control-N (i.e., hold down the control key and then type the N key) (Windows)

or Command-N (Mac OS X). This will open up a new window labeleduntitled. This window is not interactive; it is the window in which you will edit your Python programs. Click on theuntitled window to select it. Next type the following # your name # today s date # CptS 111 # Lab #1, Task print("hello, World!") print("good-bye, World!") For your name, type your name, and for today s date, type today s date. Next you need to save this program. Click onfile and selectsave or type C-S. Windows: A new window will appear that requests information about how to save your file. Click themy Documents icon that appears on the left. Then create a new folder calledcs111 by clicking on the icon in the upper right that looks like a folder with a sparkle in one corner. A new folder will appear and the text will be selected. Type CS111. Now, double click on this new folder and create another new folder called Lab1. Now double click on Lab1. Find the field labeled File name: at the bottom of the window and type hello.py. Click on the Save button or else hit thereturn key. Mac OS X: After you type C-S and thesave window opens you will see a field in which you can type the name of the file. If you don t see columns of directories and files, click on the downward-pointing arrow. The window will expand and reveal some of your directories and files. You should see Documents centered just under the writing field. Click the button labeled New Folder and type CS111 in the space for the name and then click on Create. Click again on the New Folder button, type Lab1 in the writing field, and then click Create. Finally, typehello.py in thesave As: field, and click onsave. The edit window should now be labeled hello.py. Above this window, look for the Run pulldown menu. Click on Run and then on Run Module. Alternatively, just hit the F5 function key (Windows) or fn-f5 (Mac OS X). The results of your program should now appear in the interactive window (the Python Shell window). Demonstrate that you have successfully completed this task to your TA for credit. Task 3: Body Mass Index and Metric Dimensions The body mass index (BMI) is given by the formula weight kg (height m ) In the future we will just write C-X with the understanding that C- is the control key on a Windows machine and the command key on a Mac. 3

whereweight kg is weight (or, more precisely, mass) in kilograms andheight m is height in meters. What BMI tells us about one s body or health is subject to debate, but we won t worry about this. Instead, we ll write a program that will prompt a user for his or her weight in pounds and height in inches and then report the user s BMI, weight in kilograms, and height in meters. One pound corresponds to 0.4535937 kilograms and one inch corresponds to 0.054 meters. Thus, someone who weighs 160 pounds and is six feet tall (7 inches) has a mass of roughly 7.57 kilograms and a height of 1.888 meters. Using IDLE, open a new file (C-N), and write a program that prompts the user for his or her weight and height (in pounds and inches). The user should be able to enterfloat values. Your program should convert values as necessary, calculate the BMI, and then report the BMI and the user s weight and height in metric units. For example, 1 Enter weight [pounds]: 160 Enter height [inches]: 7 3 BMI = 1.6996783839 4 Mass = 7.574779 [kilograms] 5 Height = 1.888 [meters] Here s another example (this time withfloat inputs): 1 Enter weight [pounds]: 130.5 Enter height [inches]: 69.5 3 BMI = 18.9949961478 4 Mass = 59.19380485 [kilograms] 5 Height = 1.7653 [meters] After your program is working properly, save it to yourlab1 directory. Then show it to your TA and demonstrate that it does what it should. Task 4: Calculating Your Grade We ll assume that all your assessment scores are on a 100-point scale. Then your overall score is given by: score = 0.17 exam1+0.18 exam+0.18 final +0.5 prog assign +0.08 zypa+0.0 zyca+0.1 lab where exam1 and exam are your scores on the two midterms, final is your score on the final exam,prog assign is your programming assignments score, zypa is your zybooks participation activities score, zyca is your zybooks challenge activities score, andlab is your labs score. Write a program that will prompt the user for all their scores one at a time and report their final overall score. Here are some examples: 1 Please enter the following information: 3 Exam 1 score: 100 4 Exam score: 100 4

5 Final exam score: 100 6 Programming assignments score: 0 7 zybooks participation activities score: 100 8 zybooks challenge activities score: 100 9 Labs score: 100 10 11 Your score for CptS 111 is: 75.0 1 Please enter the following information: 3 Exam 1 score: 83 4 Exam score: 84 5 Final exam score: 84 6 Programming assignments score: 100 7 zybooks participation activities score: 100 8 zybooks challenge activities score: 100 9 Labs score: 100 10 11 Your score for CptS 111 is: 91.35 When you think your program is working properly, show it to your TA and demonstrate that it works. Be sure to save it to your Lab1 directory. Task 5: Elapsed Time in Seconds and Hours Write a program that calculates the total amount of elapsed time in both seconds and hours. The program should prompt the user for an integer number of hours, an integer number of minutes, and an integer number of seconds. It should compute the total number of seconds as an integer value, and then it should compute the total number of hours as a floating-point value. The output should be separated from the input by a blank line. Here s an example result: 1 Enter the number of elapsed hours: 4 Enter the number of elapsed minutes: 31 3 Enter the number of elapsed seconds: 0 4 5 The total number of elapsed seconds: 1680 6 The total number of elapsed hours: 4.5 When you re done with your program, save it to your Lab1 directory, and make sure your TA has given you credit for this task. Congratulations on finishing your first lab! If there s time left, help others who are still struggling or else do your zybooks reading. 5