Python 14 Mr. Husch.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

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.
Game Programming © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line L.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Reading and Mapping Aerosol Data From a MODIS HDF4 File
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.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Make a function This is a starter activity and should take 5 minutes [ slide 1 ] >>> def count(number): n=1 while n
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Math operations 9/19/16.
Development Environment
Whatcha doin'? Aims: To start using Python. To understand loops.
Python 23 Mr. Husch.
Python’s Modules Noah Black.
Recap: If, elif, else If <True condition>:
More on Functions (Part 2)
A Playful Introduction to Programming by Jason R. Briggs
Python Lesson 12 Mr. Kalmes.
Writing & reading txt files with python 3
Advanced Coding Session 5
Python Lesson 12 Mr. Kalmes.
Python 18 Mr. Husch.
Python Lesson 6 Mr. Kalmes.
Python 17 Mr. Husch.
Python I/O.
Python Mr. Husch.
Python Lessons 13 & 14 Mr. Kalmes.
Functions In Matlab.
Coding Concepts (Basics)
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Module 4 Loops.
Python 9 Mr. Husch.
Lesson 3.2 Review: Identifying concepts
Python 21 Mr. Husch.
Python 17 Mr. Husch.
Python Lessons 9 & 10 Mr. Husch.
More on Functions (Part 2)
Python programming exercise
Python 19 Mr. Husch.
Introduction In today’s lesson we will look at: why Python?
Python Lesson’S 1 & 2 Mr. Kalmes.
CSCI N207 Data Analysis Using Spreadsheet
Robotics Week 4 Functions and reusable code
BO65: PROGRAMMING WRITING TO TEXT FILES.
What is x? x = 12 %
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Python 16 Mr. Husch.
Input and Output Python3 Beginner #3.
Introduction to Python
Python 3 Mr. Husch.
Chapter 1 Introducing Small Basic
Python Inputs Mr. Husch.
Python Lessons 13 & 14 Mr. Husch.
you get to solve puzzles!
Python 16 Mr. Husch.
Python 19 Mr. Husch.
Python 10 Mr. Husch.
Python 18 Mr. Husch.
Python 12 Mr. Husch.
Python 8 Mr. Husch.
Python 13 Mr. Husch.
CSCE 206 Lab Structured Programming in C
Nate Brunelle Today: Functions again, Scope
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
Starter Look at the hand-out.
Presentation transcript:

Python 14 Mr. Husch

Aim This exercise will introduce students to reading files. Understand the commands to open a file in Python

Activity What uses do the argv and raw_input ( ) commands have. You are going to be utilizing these commands to ultimately read files. Also, be cautious because working with files is an easy way to erase your work completely.

Lastname14.py

Lastname114.py Don’t forget the extra 1

Things to look at Line 1-3 should be a familiar use of argv to get a filename. Next we have line 5 where we use a new command open. Right now, run pydoc open and read the instructions. Notice how like your own scripts and raw_input, it takes a parameter and returns a value you can set to your own variable. You just opened a file. Line 7 we print a little line, but on line 8 we have something very new and exciting. We call a function on txt. What you got back from open is a file, and it's also got commands you can give it. You give a file a command by using the . (dot or period), the name of the command, and parameters. Just like with open and raw_input. The difference is that when you say txt.read() you are saying, "Hey txt! Do your read command with no parameters!"

Run in CMD To run this in CMD you need to go to your folder directory that you saved the game in. You need to type in python lastname114.py lastname14.py This will open both files, with 14 opening up inside 114.

When you run it you should see something like this Here's your file 'lesson14_sample.txt': This is stuff I typed and it’s very cool. Type the filename again: > ex15_sample.txt

Try and open an old program inside 114 Instead of using python 114.py 14.py use python 114.py and then an older file to see if it will open.

Comments in python, you need to use a # to make a comment. #This would be a comment in Python

Before turning it 1) Write what each line of code does in a comment line. 2) Try to script the raw_input ( ) section on lines 10 – 15

After turning in Keep your program up and running, we are going to have a “science fair” style showing of what you made. You will show the class your program, how you run in in CMD and the program that you choose to open in 114.