Chapter 01 Worksheet
When writing answers to questions, please use proper grammar, capitalization,
and punctuation. Please limit the length of each line to 80 characters.
1. Write a line of code that will print your name.
2. How do you enter a comment in a program?
3. What do the following lines of code output?
ALSO: Why do they give a different answer?
print(2 / 3)
print(2 // 3)
4. Write a line of code that creates a variable called pi and sets
it to an appropriate value.
5. Why does this code not work?
A = 22
print(a)
6. All of the variable names below can be used. But which ONE of these is
the better variable name to use?
a
A
Area
AREA
area
area_of_rectangle
Area_Of_Rectangle
7. Which of these variables names are not allowed in Python? (More than one
might be wrong. Also, this question is not asking about improper names, just
names that aren't allowed. Test them if you aren't sure.)
apple
Apple
APPLE
Apple2
1Apple
account number
account_number
account.number
accountNumber
account
pi
PI
fred
Fred
GreatBigVariable
greatBigVariable
great_big_variable
great.big.variable
2x
x2x
total%
8. Why does this code not work?
print(a)
a = 45
9. Explain the mistake in this code:
pi = float(3.14)
10. This program runs, but the code still could be better. Explain what is
wrong with the code.
radius = float(input("Radius:"))
x = 3.14
pi = x
area = pi * radius ** 2
print(area)
11. Explain the mistake in the following code:
x = 4
y = 5
a = ((x) * (y))
print(a)
12. Explain the mistake in the following code:
x = 4
y = 5
a = 3(x + y)
print(a)
13. Explain the mistake in the following code:
radius = input(float("Enter the radius:"))
14. Do all these print the same value? Which one is better to use and why?
print(2/3+4)
print(2 / 3 + 4)
print( 2 / 3+ 4 )
15. What is a constant?
16. How are variable names for constants different than other variable names?
17. What is a single quote and what is a double quote?
Give and label an example of both.
18. Write a Python program that will use escape codes to print a double-quote
and a new line using the Window's standard. (Note: I'm asking for the Window's
standard here. Look it up out of Chapter 1.)
19. Can a Python program print text to the screen using single quotes instead
of double quotes?
20. Why does this code not calculate the average?
print(3 + 4 + 5 / 3)
21. What is an ``operator'' in Python?
22. What does the following program print out?
x = 3
x + 1
print(x)
23. Correct the following code:
user_name = input("Enter your name: )"
24. Correct the following code:
value = int(input(print("Enter your age")))