LING 388: Computers and Language

Slides:



Advertisements
Similar presentations
CS 100: Roadmap to Computing Fall 2014 Lecture 0.
Advertisements

Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
LING 408/508: Programming for Linguists Lecture 19 November 4 th.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Lecture 17: 10/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
05/09/2015SJF L31 F21SF Software Engineering Foundations Formatting Converting numbers to Strings and vice versa Monica Farrow EM G30
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CS190/295 Programming in Python for Life Sciences: Lecture 3 Instructor: Xiaohui Xie University of California, Irvine.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
Input, Output, and Processing
Formatted Output CSE 1310 – Introduction to Computers and Programming 1.
Computer Science 101 Introduction to Programming.
5-1 Embedded Systems C Programming Language Review and Dissection III Lecture 5.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
LING 408/508: Programming for Linguists Lecture 20 November 16 th.
1.2 Primitive Data Types and Variables
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
Input and Output in python Josh DiCristo. How to output numbers str()  You can put any variable holding a number inside the parentheses and it will display.
Introduction to Programming Python Lab 5: Strings and Output 05 February PythonLab5 lecture slides.ppt Ping Brennan
5 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
CSCE Do Loops Simplest form DO j = 1,100 PRINT *,j END DO Variable j runs from 1 to 100 counting by ones.
Files in Python Opening and Closing. Big Picture To use a file in a programming language – You have to open the file – Then you process the data in the.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Physics 114: Lecture 1 Overview of Class Intro to MATLAB
Introduction to Programming
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
Input from STDIN STDIN, standard input, comes from the keyboard.
Line Continuation, Output Formatting, and Decision Structures
Formatting Output.
Programming Fundamentals
University of Central Florida COP 3330 Object Oriented Programming
Python’s input and output
Introduction to C CSE 2031 Fall /3/ :33 AM.
LING 388: Computers and Language
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
LING 388: Computers and Language
System.out.println for console output
LING 388: Computers and Language
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Line Continuation, Output Formatting, and Decision Structures
Lecture 13 Input/Output Files.
LING 388: Computers and Language
Scientific Notation.
LING 388: Computers and Language
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
IDL Tutorials Day 4 Henry (Trae) Winter
What are variables? Using input()
CMSC201 Computer Science I for Majors Lecture 18 – String Formatting
CS190/295 Programming in Python for Life Sciences: Lecture 3
Introduction In today’s lesson we will look at: why Python?
Conversion Check your class notes and given examples at class.
LING 408/508: Computational Techniques for Linguists
LING 408/508: Computational Techniques for Linguists
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Formatting Output.
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Administrative things
LING 388: Computers and Language
Introduction to Python
Presentation transcript:

LING 388: Computers and Language Lecture 12

For those using Python via an IDLE If you're wondering what directory you are in (by default): import os os.getcwd() If you want to change the working directory,use: os.chdir(path)

Last time: Homework 5 revisited http://www.bbc.com/eart h/story/20160826-why- our-ancestors-drilled- holes-in-each-others- skulls >>> import re >>> from collections import Counter >>> f = open("trepanation.txt") >>> s = f.read() >>> c = Counter([re.sub("[,.?;:\"'!]","",w) for w in s.split()]) >>> c.most_common(20) [('the', 114), ('of', 95), ('in', 38), ('a', 34), ('and', 32), ('to', 30), ('trepanation', 29), ('The', 24), ('been', 23), ('that', 23), ('skulls', 23), ('had', 22), ('have', 20), ('was', 19), ('trepanned', 16), ('skull', 16), ('all', 16), ('is', 16), ('trepanations', 15), ('were', 15)] >>> c['ritual'] 7 >>> c['rituals'] 0

Python numbers revisited page 60: see factorial.py Python 3.x Python 2.7 ( )

Python: Files Like all other programming languages, uses a file handle, called file variable: open() infile = open("file.txt","r") outfile = open("results.txt,"w")

Python: Files https://docs.python.org/3/tutorial/inputoutput.html#reading-and- writing-files

Sample text file Course webpage: falconheavylaunch.txt http://www.bbc.com/news/science- environment-42969020 Course webpage: falconheavylaunch.txt

Class Exercise Download falconheavylaunch .txt to your computer. Answer the following questions. How many characters are there in the article? How many lines of text are there in the article? How many lines excluding blank lines? How many words are there in the article? How many characters per word? What are the most common words?

Python eval() Think of eval(input()) as being the same as the user typing directly at the Python console …

Python numbers revisited factorial2.py

argv[1] and argv[2] ignored Python argv List of arguments from the command line: what's argv[0] then? test.py argv[1] and argv[2] ignored

Formatted Output: floating point (f) $100 principal for 10 years at 4% (0.04) compound interest = $148.02

Formatted Output Lots of ways: (Old way) notation comes originally from the C Programming Language: sprintf function http://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm

Now use instead: <template-string>.format(<values>) Formatted Output Now use instead: <template-string>.format(<values>) %<width>.<precision><type> <type> = d, f, s <width> = minimum number of characters; right-justified by default, -width => left-justified 0 = as wide as needed <precision> = number of places after decimal point e.g. 02d two digits wide, pad with 0 if needed

Formatted Output: examples Function str() coerces integer or float above into type 'str'

Formatted Output Newer way: https://docs.python.org/2/tutorial/inputoutput.html#fancier-output- formatting Use {} for each argument (can be numbered, e.g. {0}, {1},… or referenced by keyword {x}) {:width}

Formatted Output {0:..} and {1:…} index into the format arguments 0 in {0:..} can be omitted but not the colon