The station needs a fuel report before tonight's test flight. Rocket writes it fast. He tries to join the string "Fuel: " with the number 40, and Python stops with an error.
"Hmm," says Raven. "What do you notice? One side is a string and one side is a number."
Rocket groans, then grins. "We can improve it!" Nova flies a slow loop around the screen. "Would you like a hint? print can show more than one thing if you use commas."
You cannot join a string and a number with +. Python stops with an error.
Instead, put a comma between them inside print. print shows each one and puts a space between them.
crates = 12
crates = crates + 3
dock = "Bay 2"
print("Crates:", crates)
print("Dock:", dock) | The screen shows |
|---|
| Crates: 15 |
| Dock: Bay 2 |
Notice the space after the colon. The comma added it for us.
Rocket wants this program to show Oxygen: 30. It shows Oxygen: 25 instead.
oxygen = 25
print("Oxygen:", oxygen)
oxygen = oxygen + 5 pods = 4
pods = pods + 2
name = "Hatch A"
print("Pods:", pods)
print("Name:", name)
print("Double:", pods * 2) | Statement | True or false? |
|---|---|
| A comma in print puts a space between the values. | ? |
| print("Tanks:", 3) shows Tanks:3 with no space. | ? |
| Python can do math inside print. | ? |
| A print line shows what is in a box at that moment. | ? |
Week one is done, Crew Engineer! You can print, store, change and join values. Next week you will keep many values in one list.