Python Arena
Step 1 of 6

Joining and repeating strings

You've joined strings with + already. Python calls this concatenation: the strings are put one after the other, exactly as they are. Nothing is added between them, so any space has to be inside one of the strings:

first = "sun"
second = "flower"
print(first + second)
print(first + " " + second)
Output
sunflower
sun flower

Repeating a string with *

The * operator works on strings too, when the other side is a whole number: it repeats the string that many times.

print("ha" * 3)
print("-" * 20)
print("=" * 5 + " Menu " + "=" * 5)
Output
hahaha
--------------------
===== Menu =====

As with numbers, * comes before +, so on the last line Python first repeats the two = strings and then joins the three pieces.

The number can be a variable, which makes * handy in loops. This loop draws a triangle, one # wider in every round:

width = 1
while width <= 4:
    print("#" * width)
    width += 1
Output
#
##
###
####

Numbers from input

A string can only be repeated a whole number of times. input always gives a string, even when the user types digits, so forgetting int stops the program:

width = input("Width: ")
print("*" * width)
Input
6
Output
Width: 6
Python stops with
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    print("*" * width)
          ~~~~^~~~~~~
TypeError: can't multiply sequence by non-int of type 'str'

A sequence is Python's word for a value that holds things in order, as a string holds its characters. The message says that * got a string on its other side ('str') where it needs an int. With width = int(input("Width: ")) the program works.

Your task

Challenge 1 of 3

Fill in the blank so the program prints a line of 12 = characters under the title, as long as the title itself.

Python Arena
============

Challenge 2

What does this program print? Type each line it prints.

Challenge 3

Write a program that asks for a width and a height and draws a box. The top and the bottom line are a +, then as many - characters as the width, then another +. Between them come as many lines as the height, each one a |, as many spaces as the width, and another |.

Width: 5
Height: 2
+-----+
|     |
|     |
+-----+