lect01 Next Lecture

Resources from lecture

Intro to Course Logistics

Learning Something New

Intro to the Unix environment

Getting started with Python and IDLE

Also called the Python Shell Prompt


Python 3.4.3 (default, Aug  9 2016, 15:36:17)
[GCC 5.3.1 20160406 (Red Hat 5.3.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + 3
5
>>> 2 + 7 *4
30
>>> 2 ** 3
8
>>> 2 ** 3 ** 2
512
>>> 2 * 3 * 4
24
>>> (2 * 3) * 4
24
>>> 2 * (3 * 4)
24
>>> (2 ** 3) ** 2
64
>>> 2 ** (3 ** 2)
512
>>>

Note that ** is right associative, not left associative.

Numerical type examples (type these in the shell to see what happens)


>>> 1

>>> 1+2

>>> 4/2

>>> 1/3

>>> 6/2

>>> 1/0

>>> 1+2*4

Storing data using variables

>>>x = 10 #What is the value of x?

>>>x = x * 10 # 10 * current value of x is stored back into x


More than just a calculator

x = 1
print(x)
print(type(x))

x = 4 / 2
print(x)
print(type(x))

y = 4 * 2
print(y)
print(type(y))

z = 4 * 2.0
print(z)
print(type(z))

x = "CS 8"
print(x)
print(x*2)

x = "8.0" # string not float
print(x) #8.0
print(type(x)) #str

print(x + 2) #ERROR
print(x + "2") # No error, uses concatenation

print(float(x) + 2) # No error, 10.0

x = "8.0" # Be careful ...
print(int(x)) #crashes

x = "8"
print(int(x))

x = "8.0"
y = "8.0"
z = "8.00"

print(x == y) #True
print(x == z) #False
print(float(x) == float(z)) #True
print(2 * 3 > 5) #True
print(type(2 * 3 > 5)) # bool

Interacting with a program using print and input

```python

Example

print(“Hi, please enter your name: “) userName = input() print(“Hello”, userName)