Chapter 2- Types, Variables, Memory, Simple Input and Output
I. Basic Programming
Input Process Output
# Demonstrates the use of quotes in strings
print("Program 'Game Over' 2.0")
print("Same", "message", "as before")
print("Here", end=" ")
_____ ___ ___ ___ _____
/ ___| / | / |/ | | ___|
| | / /| | / /| /| | | |__
| | _ / ___ | / / |__/ | | | __|
| |_| | / / | | / / | | | |___
\_____/ /_/ |_| /_/ |_| |_____|
_____ _ _ _____ _____
/ _ \ | | / / | ___| | _ \
| | | | | | / / | |__ | |_| |
| | | | | | / / | __| | _ /
| |_| | | |/ / | |___ | | \ \
\_____/ |___/ |_____| |_| \_\
When you put quotes around something, Python takes it literally. It prints exactly what is in the quotes. You can use double quotes or single quotes for a string.
teacher = “Mrs. Heineman” or teacher = ‘Mrs. Heineman’
You can print multiple values with a comma in-between strings for example:
print ( “Same”, “message”, “ as before”) A space is automatically placed between the words.
Concatenate- adding together strings
i. print “cat” + “dog would show catdog
open Silly string program
Long Strings- triple quoted string
Use when you have several lines of text that you want displayed together
longString=””” Sing a song of sixpence, a pocket full of rye,
Four and twenty black birds baked in a pie.
When the pie was open, the birds began to sing.
Wasn’t that a dainty dish to set before the king?””
B. Escape Sequences with Strings
a. allows you to put special characters into your strings.
b. made up of two characters: a backslash followed by another character.
With the variables teacher and Teacher, are they the same?
Is “Hello” the same as ‘Hello’ in Python?
Which of the following is not a correct variable name? Why?
Is “10” a number or a string?
Is ‘4’ the same as 4 to Python?
State the output.
Fix the statement so it converts to stated data type.
age=input(“Enter age”) #convert age to an integer
Write a valid variable name for the following – state its data type.
Your grade point average.
Number of students in school
Your phone number
Chapter 2 Programs.
For each program make comments at the top with your name and the program’s name.
Use proper variable names
Make output “look nice”. It should never be just a number. For example:
print(“The total amount is $”,total)
Save all programs with proper name in your folder.
Make a program that assigns your first name to the variable firstName; last name assigned to variable lastName and then display your first and last name with a space inbetween.
Tipper Program- Write a program where the user enters the total of the bill from a restaurant order. The program should then display two amounts; a 15% tip and a 20% tip.
Write a car salesman program where the user enters the base price of a car. The program should add on extra fees such as tax, dealer prep and destination charge. Make the tax be 7% of the cost of the car, dealer prep is $250 and destination charge is $130.50. Display the actual price of the car once everything is added in.
Write a program that has the user input an amount in change less than one dollar. The program should output the number of quarters, dimes, nickels and pennies used for that amount. Assume it will give the most possible of the largest coins. For example: 92 is the inputted value.