Class Day 1 - Python Syntax

Day #1 - Class Notes

Heading

These are my notes using Markdown

In [1]:
# Add decimal point to keep fraction when dividing

5/2.0
Out[1]:
2.5
In [2]:
print "Day 1 of class print function"
Day 1 of class print function
In [3]:
# Determine type of variable

a = 2
type(a)
Out[3]:
int
In [4]:
b = 2.45
type(b)
Out[4]:
float
In [5]:
c = True
d = False
print type(c)
print type(d)
<type 'bool'>
<type 'bool'>
In [6]:
type("String")
Out[6]:
str
In [7]:
str1 = "String 1"
str2 = "String 2"
str_combined = str1 + " " + str2
print str_combined
String 1 String 2
In [8]:
# Percent sign gives you the remainder when dividing integers

10 % 4
Out[8]:
2
In [9]:
# Use Double Asterics for Exponents

10 ** 2
Out[9]:
100
In [10]:
2**4
Out[10]:
16
In [11]:
# Scientific Notation

1e4
Out[11]:
10000.0
In [12]:
9e4
Out[12]:
90000.0
In [13]:
12.45e6
Out[13]:
12450000.0
In [14]:
12.45E6
Out[14]:
12450000.0

Code Code code

In [15]:
my_Name = "Nolan"
print "My name is " + my_Name
My name is Nolan
In [16]:
print "I am",my_Name
I am Nolan
In [17]:
print "I am {}".format(my_Name)
I am Nolan
In [18]:
Albert = "Albert"
print "Hello {0}, I am {1}".format(Albert,my_Name)
Hello Albert, I am Nolan
In [19]:
print "Hello {a}, I am {b}".format(a=Albert,b=my_Name)
Hello Albert, I am Nolan
In [20]:
print "Hello {0}, I am {1}".format("Albert","Nolan")
Hello Albert, I am Nolan
In [ ]:
print "Hello {banana}".format(banana=my_Name)
In [ ]:
prepared = ""
while prepared != "Y" and prepared != "N":
    prepared = raw_input("Hello, are you ready to order? (Y/N)")
In [ ]:
if prepared == "Y":
    order = ""
    while order != "Fish Burger" and order != "Big Mac" and order != "Salad":
        order = raw_input("Would you like a Fish Burger, Big Mac, or Salad?")
    if order == "Fish Burger" or order == "Big Mac":
        upsize = raw_input("Would you like to upsize the fries and drink with your {}? (Y/N)".format(order))
        if upsize == "Y":
            print "Okay. That will be a {} with upsized fries and drink. Your food will be ready soon. Please come again!".format(order)
        else:
            print "Okay. That will be a {} with small fries and drink. Your food will be rady soon. Please come again!".format(order)
    elif order == "Salad":
        print "Sounds good! Your total price will be $2.75."
    else:
        print "Please ensure you spelled your order correctly."
else:
    print "Okay. Please let me know when you are ready to order."
Would you like a Fish Burger, Big Mac, or Salad?sald
Please ensure you spelled your order correctly.
In [ ]:

rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora