Python for Informatics: Exploring Information

Slides:



Advertisements
Similar presentations
Input and Output Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Advertisements

Computer Science 101 While Statement. Iteration: The While-Statement The syntax for the While- Statement is while : The syntax for the While- Statement.
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Conditional Execution
Chapter 8 Improving the User Interface
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Reading Files Chapter 7 Python for Informatics: Exploring Information
Handling Errors Introduction to Computing Science and Programming I.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Computing Theory: BBC Basic Coding Year 11. Lesson Objective You will: Be able to define what BBC basic is Be able to annotate BBC basic code Be able.
Variables, Expressions, and Statements
DIRAC API DIRAC Project. Overview  DIRAC API  Why APIs are important?  Why advanced users prefer APIs?  How it is done?  What is local mode what.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
Group practice in problem design and problem solving
An Introduction to Textual Programming
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 13 Files and Exception Handling 1.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
General Programming Introduction to Computing Science and Programming I.
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Python for Informatics: Exploring Information
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Regular Expressions Chapter 11 Python for Informatics: Exploring Information
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Functions Chapter 4 Python for Informatics: Exploring Information
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Variables, Expressions, and Statements
Variables, Expressions and Statements
Conditional Execution Chapter 3 Python for Informatics: Exploring Information
1 Program Input Software Design Chapter 4. 2 You Will Want to Know... Prompting for and reading values into a program. Accessing data from a file. What.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Functions Chapter 4 Python for Informatics: Exploring Information Slightly modified by Recep Kaya Göktaş on March 2015.
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Getting Started With Python Brendan Routledge
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Reading Files Chapter 7 Python for Everybody
Agenda Introduction Computer Programs Python Variables Assignment
Conditional Execution
Data Types and Conversions, Input from the Keyboard
Functions Chapter 4 Python for Everybody
Variables, Expressions, and Statements
Python for Informatics: Exploring Information
Conditional Execution
Strings Chapter 6 Slightly modified by Recep Kaya Göktaş in April Python for Informatics: Exploring Information
When I want to execute the subroutine I just give the command Write()
Conditional Execution
Conditional Execution
Python for Informatics: Exploring Information
Variables, Expressions, and Statements
Python for Informatics: Exploring Information
Introduction to Programming with Python
Variables, Expressions, and Statements
A LESSON IN LOOPING What is a loop?
Introduction to Computer Science
Input and Output Python3 Beginner #3.
CHAPTER 6 Testing and Debugging.
Introduction to Computer Science
Presentation transcript:

Python for Informatics: Exploring Information Worked Exercises Python for Informatics: Exploring Information www.pythonlearn.com

Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/. Copyright 2010, Charles Severance

Exercise Rewrite your pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters ( hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 475 = 40 * 10 + 5 * 15

Using These Exercises. Try the exercise yourself for a while before you use these worked exercises.... If you just take the “easy way out” for the easy exercises, then you won’t build the skills for the later exercises. Another approch

www.pythonlearn.com Installing Python Installing your text editor (NotePad++ or TextWrangler) Setting tab expansion Using the Command Line or Terminal Interface Editing and running Python Programs

Exercise 2.3 Write a program to prompt the user for their name and welcome them. Enter your name: Chuck Hello Chuck

Exercise 2.4 Write a program to prompt the user for hours and rate per hour to compute gross pay. Enter Hours: 35 Enter Rate: 2.75 Pay: 96.25

Exercise 3.1 Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Enter Hours: 45 Enter Rate: 10 Pay: 475.0 475 = 40 * 10 + 5 * 15

Exercise 3.2 Rewrite your pay program using try and except so that your program handles non-numeric input gracefully. Enter Hours: 20 Enter Rate: nine Error, please enter numeric input Enter Hours: forty

Exercise 5.1 Write a program which reads list of numbers until ``done'' is entered. Once ``done'' is entered, print out the total, count, and average of the numbers. If the user enters anything other than a number, print an error message and skip to the next number. Enter a number: 4 Enter a number: 5 Enter a number: bad data Invalid input Enter a number: 7 Enter a number: done Average: 5.33333333333

Write some code to parse lines of the form: X-DSPAM-Confidence: 0.8475 Exercise 6.9 Write some code to parse lines of the form: X-DSPAM-Confidence: 0.8475 Use find and string slicing to extract the portionof the string after the colon character and then use the float function to convert the extracted stringinto a floating point number. http://www.pythonlearn.com/code/mbox-short.txt

Enter a file name: mbox-short.txt Exercise 7.3 Write a program to read through a file and print the contentsof the file (line by line) all in upper case. Executing the program will look as follows: Enter a file name: mbox-short.txt FROM STEPHEN.MARQUARD@UCT.AC.ZA SAT JAN 5 09:14:16 2008 RETURN-PATH: <POSTMASTER@COLLAB.SAKAIPROJECT.ORG> RECEIVED: FROM MURDER (MAIL.UMICH.EDU [141.211.14.90]) BY FRANKENSTEIN.MAIL.UMICH.EDU (CYRUS V2.3.8) WITH LMTPA; SAT, 05 JAN 2008 09:14:16 -0500 http://www.pythonlearn.com/code/mbox-short.txt

Exercise 7.4 http://www.pythonlearn.com/code/mbox-short.txt Write a program to loop through a mailbox-format file and look for lines of the form: X-DSPAM-Confidence: 0.8475 Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number. Count these lines and the compute the total of the spam confidence values from these lines. When you reach the end of the file, print out the average spam confidence. Enter the file name: mbox.txt Average spam confidence: 0.894128046745 Enter the file name: mbox-short.txt Average spam confidence: 0.750718518519 Exercise 7.4 http://www.pythonlearn.com/code/mbox-short.txt