Date

Lecture Date: Wednesday, September 7

Now that we are through the break-neck pace of trying out a lot of stuff with turtle, we're going to slow down and go step-by-step and see how we can put programs together.

Today, we'll focus on input and output with a program.

Let's first start by discussing literals. A literal is a value that appears in a program that is what it is. For instance, if I say:

print("Hello World!")

then "Hello World!" is a literal. It is the actual value of the thing it represents. In this case, we would call this a string. You can print any literal to the screen using the print method as shown above.

When we look at string literals, notice how it is surrounded by quotation marks. We'll examine that a bit more in class.

Next, we'll discuss variables and value assignment with the equals sign. What makes a good variable name? What can variables hold? Can they hold different types of items? We'll touch on dynamic vs. static typing. Then we'll discuss how to print them along with how to combine the printing of multiple items.

How do we get input from the user? Well, with the input command! We'll do some more examples here and do some basic arithmetic using Python.

The information for today's lecture comes from Chapter 2 of the Gaddis book.

# Mark Sherriff (mss2x)

print("Python is awesome!")
print('Python is awesome!')
print('"Python is awesome!"')

statement = "Python is awesomer!!!!"

print(statement)

statement = 4
print(statement)

number_of_slices_of_bacon = 100
badVariableName = "Java"

statement = 3.1419


# Write statements that do the following:
# add two integers
print(5 + 9)
print("Mark " + "Sherriff")

# multiply two floating point numbers
print(3.234243 * 56.2423423)

# divide two floating point numbers
print(9.5 / 2.3)
print(format(9.5 / 2.3, ".7f"))

# raise a integer to an integer power
print(2 ** 3)

# find the remainder of division of 25 / 6
print(25 % 6)

print(6 // 4)
print(6 / 4)

name = input("What is your name? ")
print("Hello, " + name)

number = input("Give me a number between 0 and 100: ")
print(type(number))
print(int(number) + 4)