CompSci 6 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Advertisements

James Tam Introduction To Files In Python In this section of notes you will learn how to read from and write to files in your programs.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Python
Chapter 2 Writing Simple Programs
Compsci 101, Spring COMPSCI 101, Spring 2012 Introduction to Computer Science Owen Astrachan
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Bell Ringer What types are numbers are there is the python programming language?
The if statement and files. The if statement Do a code block only when something is True if test: print "The expression is true"
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Lecture 06 – Reading and Writing Text Files.  At the end of this lecture, students should be able to:  Read text files  Write text files  Example.
9/16/2015BCHB Edwards Introduction to Python BCHB Lecture 5.
Strings CS303E: Elements of Computers and Programming.
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
CS 177 Week 4 Recitation Slides Variables, Files and Functions.
How to Read Code Benfeard Williams 6/11/2015 Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger.
CompSci 6 Introduction to Computer Science Sept 29, 2011 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not.
JSON COMPSCI 105 SS 2015 Principles of Computer Science.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
1 CSC 221: Introduction to Programming Fall 2011 Input & file processing  input vs. raw_input  files: input, output  opening & closing files  read(),
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science March 24, 2016 Prof. Rodger compsci 101, spring
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger Lecture today by Sriram Vepuri.
Input, Output and Variables GCSE Computer Science – Python.
Fundamentals of Python: First Programs
CompSci 101 Introduction to Computer Science
Python: Experiencing IDLE, writing simple programs
CompSci 101 Introduction to Computer Science
Introduction to Python
For loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
CompSci 101 Introduction to Computer Science
(optional - but then again, all of these are optional)
Python: Control Structures
CompSci 101 Introduction to Computer Science
(optional - but then again, all of these are optional)‏
Python’s input and output
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Functions CIS 40 – Introduction to Programming in Python
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
For loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble Notes for 2010: I skipped slide 10. This is.
Topics Introduction to File Input and Output
Introduction to Computer Science
CompSci 101 Introduction to Computer Science
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
CompSci 101 Introduction to Computer Science
Introduction to C Programming
Topics Introduction to File Input and Output
Benfeard Williams June 16th, 2016
Topics Introduction to File Input and Output
Presentation transcript:

CompSci 6 Introduction to Computer Science September 6, 2011 Prof. Rodger Don’t put all the slides on handout!!!! Skip 7 and 10 compsci 6 fall 2011

Announcements Read for next time Chap 3 Reading Quiz (RQ 2) on Blackboard Due before class next time Lab 2 starts Thursday compsci 6 fall 2011

Python – Programming Concepts Names vs abstractions What is http://152.3.140.1 What is http://www.amazon.com Types are important What is foo.pdf, foo.mp4, foo.jpg, foo.wav Do the file extensions guarantee file type? Python first = "Susan" x = 6 y = 3.4 compsci 6 fall 2011

Review(modified) – Names/Types def countWords(filename): fff = open(filename) sss = fff.read() words = sss.split() unique = set(words) print "filename: ", filename print "total # words = ",len(words) print "unique # words = ",len(unique) countWords(‘romeo.txt') What are names and their types? Questions? compsci 6 fall 2011

Function – define vs call def functionName(parameters): block def sum(a, b): return a+b Call function sum(7, 4) sum(“a”, “cat”) Advantages Repeat code, call multiple times Flexible, call with different arguments

Strings Sequence of characters in quotes "I" 'Love' '''Python''‘ String operators: concatenation (+), repeat(*) Precedence? "a" + "b" "c" * 3 Format output - %f %d %s count = 3.0 print "There were %d winners" % count

Strings Sequence of characters in quotes "I" 'Love' '''Python''' 'ILovePython' String operators: concatenation (+), repeat(*) Precedence? "a" + "b" "c" * 3 'abcbcbc' Format output - %f %d %s count = 3.0 print "There were %d winners" % count There were 3 winners

User Input Request input using raw_input() Input is a string value = raw_input() If want a number, must convert int(raw_input()) float(raw_input()) Encourage you to experiment with commands compsci 6 fall 2011

Example >>> ttemp = raw_input("temp?=") >>> type(temp) >>> temp * 3 >>> temp = int(temp) compsci 6 fall 2011

Example >>> ttemp = raw_input("temp?=") temp?=67 >>> type(temp) <type 'str'> >>> temp * 3 '676767‘ >>> temp = int(temp) 201 compsci 6 fall 2011

Problem Solving Given a problem Algorithm Write an algorithm first Then convert to Python code Algorithm Description in words of how to solve the problem Think, What do you need? File, function, input? Try to be precise compsci 6 fall 2011

Classwork 3: Write programs for time and theater compsci 6 fall 2011