ecs10-10-1 - Announcements ECS 10 10/1 First First...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Announcements ECS 10 10/1 First First assignment due tonight, 10pm Next Next assignment on Web page tomorrow AM Last Time Data Data types Integers, eg. Integers, eg. 87 Floating Floating point numbers, eg 6.78 Stings eg Call me taxi! Stings, eg. “Call me a taxi!” print print Integers vs strings 5 5 is an integer. ‘5’ is a string. Fiona Fiona is a dog. ‘Fiona’ is a string. Python Python commands Program Program Today - variables x=5 Assigns the integer 5 to the variable x The variable is on the left The value assigned to the variable is on the right. Expressions and values 34+57 34+57 is an expression. expression. Its Its value is 91 6.2 6.2 is an expression Its value is 6.2 Its value is 6.2 “Coca“Coca-cola” is also an expression Either Either kind of expression can be assigned to variables. We We say Python evaluates an expression when it computes its value. Its Its value is “Coca-cola” “Coca- 1 Why variables? One One reason – You can assign a value in one place and use it lots of places. So its easy to change the value later. Concatenation Concatenation An An operator on strings “My “My “+”cat” is a string expression that has the value “My cat” “Gilli “Gillian”+”,” has the value “Gillian,” th “Gilli Different ways to skin a… Here Here are three ways to do the same thing print print “My cat“,catName print “My cat “+catName print My cat print print “My cat“, print catName (this one works only in programs, not in the IDLE window. The comma prevents going to a new line). The The user The person running the program. Getting data from the user x = raw_input(‘Enter a name: ‘) The The user enters a string The The string is assigned to the variable x The The only kind of data you can get is strings! raw_input() raw_input() makes a string >>> x = raw_input(“Enter a number: ") enter a number: 5 >>> x '5‘ x is assigned the string ‘5’ 2 Why variables? One One reason – You can assign a value in one place and use it lots of places. So its easy to change the value later. Reason Reason 2 – you can get a data from you can get data from the the user and refer to it in your program. Enter Enter to exit Many Many examples in the book end with: raw_input(“Press raw_input(“Press enter to exit”) Python Python waits for the user to enter something. As soon as the user hits the enter key, the program is done and it exits. Nice Nice in Windows! 3 ...
View Full Document

This note was uploaded on 03/23/2011 for the course ECS 10 taught by Professor Amenta during the Winter '07 term at UC Davis.

Ask a homework question - tutors are online