Algo DombitLearn by building
Loading your work...
Python - Lesson 1 - Homework 01

Print it. Predict it.
Fix it. Build it.

A first Python homework on arithmetic, print(), data types, casting, common errors, and string operations.

print("Small steps", "real code", sep=" -> ")
What you will practise
  • Use arithmetic operators correctly
  • Control output with sep and end
  • Recognise str, int, and float
  • Fix syntax and type errors
How to complete it
  1. Predict before running code.
  2. Check in Python.
  3. Correct your mistakes.
  4. Finish the three programs.
Part A

Run the code in your head

Write the exact output. Then choose the result type.

12 points

1Addition

print(8 + 5)
Result type

2Subtraction

print(14 - 9)
Result type

3Multiplication

print(6 * 4)
Result type

4Division

print(17 / 5)
Result type

5Floor division

print(17 // 5)
Result type

6Power

print(2 ** 5)
Result type

7Order matters

print(2 + 3 * 4)
Result type

8Parentheses

print((2 + 3) * 4)
Result type

Type check

Choose string, integer, or floating-point for each value.

"42"
Type
42
Type
42.0
Type
"Alice"
Type
-7
Type
3.14
Type
Partial result

Check this part without submitting the full homework.

Part B

Control the output with print()

Write exact output with normal spaces and line breaks.

12 points

1Default separator

print("Ali", "Vali")

2Custom separator

print("Ali", "Vali", sep="+")

3One line, then a new line

print("A", end="")
print("B")
print("C")

4sep and end together

print("Python", "Lesson", "1", sep=" | ", end="!")

5Two print calls, one line

print("Dombit", end=" -> ")
print("Python")

6Think carefully

print("A", "B", sep="", end="-")
print("C", end="!")

Write the print statement

Use the requested print() options.

7Produce: red|green|blue

Use one print() and sep.

8Produce: Loading...DONE

Use two print() calls and end.

9Produce: A-B-C!

Use one print(), sep, and end.

Partial result

Check this part without submitting the full homework.

Part C

Bug lab: will it run?

Choose RUNS or ERROR. Explain the result and add a corrected line or exact output.

12 points

1Missing quote

print('Alice)
Will it run?

2String + integer

name = "Alice"
age = 42
print(name + age)
Will it run?

3String x string

print("ha" * "3")
Will it run?

4Looks suspicious

print("Alice" + "42")
Will it run?

5Float inside concatenation

score = 9.5
print("Score: " + score)
Will it run?

6end needs a string

print("A", end=!)
Will it run?

7One argument only

print("Dombit", sep="-")
Will it run?

8Casting first

age = 42
print("Age: " + str(age))
Will it run?
Remember Newer Python versions usually say unterminated string literal for an unclosed quote.
Partial result

Check this part without submitting the full homework.

Part D

String workshop

Predict each result, then build a small banner.

10 points

1Predict the output

print("Py" + "thon")

2Predict the output

print("ha" * 4)

3Predict the output

print("-" * 10)

4Predict the output

print("A" + "B" * 3)

5Predict the output

print(("A" + "B") * 3)

6Predict the output

print("Dombit " * 3)

7Complete the banner

Fill in the code so it prints a 20-character border and the line Dombit Python.

print("=" * _____)
print("Dombit" + _____ + "Python")
print("=" * _____)

8Write your own

Create a three-line banner for your name. Use concatenation, string multiplication, and at least 16 characters per line.

Partial result

Check this part without submitting the full homework.

Programs

Build three Python files

Use variables so each program updates automatically when starter values change.

54 points
Program 1

Dombit Student Card

student_card.py

Starter variables

name = "Aziza"
group = "Python-1"
age = 15
average = 92.5

Required output

============================
DOMBIT STUDENT CARD
Name: Aziza
Group: Python-1
Age: 15
Average: 92.5
============================
  • Create the border with "=" * 28
  • Use sep="" and end="" at least once
  • Use str(age) in one concatenation
  • Do not hard-code the variable values in output strings
Program 2

Dombit Mini Calculator

mini_calculator.py

Starter code

a = 17
b = 5

Required output

A = 17 | B = 5
A + B = 22
A - B = 12
A * B = 85
A / B = 3.4
A // B = 3
B ** 2 = 25
  • Use all six operators: + - * / // **
  • Calculate inside the print() calls
  • Use sep="" and do not hard-code any answers
Program 3

Mad Line: The Python Lesson

mad_line.py

Starter variables

student = "Aziza"
topic = "Python"
times = 3
score = 9.5

Required output

Aziza entered Dombit and opened Python.
"Practice!" appeared 3 times:
Practice! Practice! Practice!
Her first score was 9.5/10.
  • Use all four variables and cast times and score
  • Use string multiplication for the practice line
  • Use single and double quotes correctly
  • Produce exactly four output lines
Bonus +2

Pixel badge

++++++++++++++
+   DOMBIT   +
++++++++++++++

Reflection

Which error was easiest to understand? Which one was hardest, and what did the error message help you notice?

Partial result

Check this part without submitting the full homework.

Homework 01

Ready to finish?

Complete every required answer, then mark the lesson as finished. Your teacher can review the answers from this browser.