New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Weeks 1 and 2 Notes

by: Eunice

Weeks 1 and 2 Notes CS 1110-002

View Full Document for 0 Karma

View Full Document


Unlock These Notes for FREE

Enter your email below and we will instantly email you these Notes for Intro to Computing using Python

(Limited time offer)

Unlock Notes

Already have a StudySoup account? Login here

Unlock FREE Class Notes

Enter your email below to receive Intro to Computing using Python notes

Everyone needs better class notes. Enter your email and we will send you notes for this class for free.

Unlock FREE notes

About this Document

Since the first week of classes had only one lecture, I've put week 1 and 2 together.
Intro to Computing using Python
Lee, Van Loan
Class Notes
Python, CS, Computer Science




Popular in Intro to Computing using Python

Popular in ComputerScienence

This 5 page Class Notes was uploaded by Eunice on Tuesday January 19, 2016. The Class Notes belongs to CS 1110-002 at Cornell University taught by Lee, Van Loan in Spring 2016. Since its upload, it has received 171 views. For similar materials see Intro to Computing using Python in ComputerScienence at Cornell University.

Similar to CS 1110-002 at Cornell

Popular in ComputerScienence


Reviews for Weeks 1 and 2 Notes


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 01/19/16
CS 1110 Introduction to Python Lee and Van Loan Spring 2016 January 28, 2016  Assignment Statement and Types o Python’s Interactive Mode: ex.  >>> r = 10  >>> A = 3.14*r**2  >>> print A o Variables, Expression, Assignments  r and A are variables  define variable: a named memory location, like a box, holds a value  define = : assignment statement  variables are used in an expression o expression: evaluated and then stored under assigned variable o ex. 3.14*r**2  order is important  variable must be assigned a value before it is used and evaluated in an expressed o >>> A = 3.14*r**2 o >>> r = 10 o NameError: name ‘r’ is not defined  Assigning is different from “equal to” o >>>3.14*r**2 = A o SyntaxError: can’t assign to an operator  Difference between math and python  Overwriting works  >>> r = 10  >>> A = 3.14*r**2  >>> A = A/2  <variable name> = <expression>  Evaluate right item and store it in left item  Rules of naming variables  Name must be digits, uppercase letters, low care letters and _ (underscore)  Must begin with a letter or _  Expressions: use parentheses if there is ambiguity o Types  Python views numbers as a type  int: integer, integer arithmetic is exact  float: float arithmetic is usually inexact  literals  Int: ex. 12  Float: ex. 12.0  Str: ex. abc  Operations  Int: + - * / unary- ** %  Float: + - * / unary- **  Str: + o Ints and floats  Integers v. decimals and python arithmetic  Integer division: A/B = Q and R (a remainder) o >>> r = x%y o r is printed as a remainder  >>> x = 30  >>> y = 8  >>> q = int(x)/int(y)  >>> print q  3  >>> q = x/y  >>> print q  3  Decimal division: A/B = Q (a decimal)  >>> x = 30  >>> y = 8  >>> q = float (x)/ float (y)  >>> print q  3.75  Clock arithmetic  Float can represent an integer even though it is not an integer type o Strings  Strings: quoted characters  >>> s1 = ‘abc’  >>> s2 = ‘ABC’  >>> s3 = ‘ A B C ‘  s1, s2, s3 are variables  a single character is a string  define subscripting: characters in a string can be referenced through their indices (USE BRACKETS) o >>> s = ‘The Beatles’ o >>> t = s[4] o >>> print t o B  “t is a slice of s” o >>> s = ‘The Beatles’ o >>> t = s[4:8] o >>> print t o Beat o >>> s = ‘The Beatles’ o >>> t = s[4:] o >>> print t o Beatles o >>> s = ‘The Beatles’ o >>> t = s[:4] o >>> print t o The  Concatenation: string analog of addition (unlimited) o >>> s1 = ‘The’ o >>> s2 = ‘Beatles’ o >>> s = s1+s2 o >>> print s o TheBeatles o >>> s1 = ‘The’ o >>> s2 = ‘Beatles’ o >>> s = s1+’ ‘+s2 o >>> print s o The Beatles  Data is provided often in strings and must be converted  >>> s= ‘123.45’  >>> x = 2*float(s)  >>> print x  246.90 February 2, 2016  two modes in python o script vs interactive o code to be run (script) is entered into a file (module) o .py file suffix  Example: windchill calculation o Compute windchill temperature given temperature, wind speed o Define variables and the model, print the result  “ “ “computes wind chill as a function of wind (mph) and temp (Fahrenheit).” “ “  Temp = input(‘Enter temp (Fahrenheit):’) # temperature in Fahrenheit  Wind = inpute(‘Enter wind speed (mph):’) # wind speed in miles-per-hour  A= 35.32; B=.6215; C=-35.74; D.42275; e=.16 # model parameters  wc=(A+B*temp) + (C+D*Temp)*Wind**e # compute and display the wind chill  Print wc o Comments begin with a “#”, guidelines o Docstrings: three quotation marks “”” o To print with formatting  Print ‘ windchild:%4.Of’ [CHECK SLIDES] o Import functions from modules  Ex. sqrt function from math module  From math import sqrt, pi  Practice with demo files    Begin all modules o Name of module ( o Name and net id (#name netid) o Date (#December 25, 2016)  Conditional execution o If-Else  a=input(‘Enter a pos float:’)  b=input(‘Enter a pos float:’)  aTob=a**b  bToa=b**a  if aTob>bToa: #aTob>bToa is a boolean expression which is either True or False  print aTob  Else:  Print bToa o The punctuation and indentation are essential o You do not need variables, you can have expressions  If boolean expression:  Statements to execute if the expression is True  Else:  Statements to execute if the expression is False February 4, 2016  Conditional execution o Remember, indentation is important  If something isn’t indented, it’s a new statement/task that will be executed o When comparing two expressions to see if they have exactly the same value, use ==  = is an assignment  == is a comparison o < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to), == (is equal to), != (not equal to)  No spaces  Alphabetical/string comparison:  Comes first in alphabet: <  capital letter is < a lower case letter  0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij klmnopqrstuvwxyz o If-Elif-Else construction  Elif: “else if”  How it works o An input is evaluated by each condition, until it reaches a comparison that verifies as True o Once a condition is evaluated as True, it stops and executes the statement  If boolean expression:  Statements to execute if this expression is True  Elif another Boolean expression:  Statements to execute if this expression is True  Else:  Statements to execute if all above expressions are False  “Elif”s are unlimited  len function o N = len(string)  N now has been assigned the value of the length of the string  Finding a solution: deriving by stepwise refinement o Reformat the task (use pencil and paper and write out a potential solution in stylized English)  Ex. hyphenator  Read in the string  Compute its length  If the length is even  Hyphenate in the middle  Else  Hyphenate around the middle character o Refine (USE COMMENTS)  h = input (‘Enter a string: ‘)  n = len(s)  If n%2==0:  # s has even length  m = n/2  h = s[:m] + ‘-‘ + s[m:]  Else:  # s has odd length  m = n/2  h = s[:m] + ‘-‘ + s[m] + ‘-‘ + s[m+1:]  Logical operators


Buy Material

Are you sure you want to buy this material for

0 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Janice Dongeun University of Washington

"I used the money I made selling my notes & study guides to pay for spring break in Olympia, Washington...which was Sweet!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.