In a modify task you take code that already works and adapt it so that it does something else.
The editor starts you off with a counter loop that prints part of the six times table:
number = 6
counter = 1
while counter < 13:
print(counter * number)
counter = counter + 1
Run it first to see what it does. It prints twelve bare numbers, and it is not easy to tell what any of them mean.
Adapt the code so that the user picks the number, the output explains itself, and the counter goes up in twos.
number = 6 with two lines: a print that asks the question, and a
line that reads the answer with input() and wraps it in int() so that it
can be multiplied. Ask the question with its own print, exactly as
written:
Which times table would you like?
print line so that instead of a bare number it prints the number,
the counter and the two of them multiplied together, as a sentence.The loop has finished. It must not
be indented, so that it runs once, when the loop is over.Leave the counter = 1 line and the while counter < 13: condition exactly as
they are.
Each line inside the loop is worded exactly like this, where NUMBER is what
the user typed, COUNTER is the value of the counter on that time round, and
PRODUCT is the two of them multiplied together:
NUMBER multiplied by COUNTER equals PRODUCT
The counter starts at 1 and goes up in twos while it is still below 13, so it takes the values 1, 3, 5, 7, 9 and 11. Your program therefore prints six of those lines, and then this one:
The loop has finished
Input:
6
Output:
Which times table would you like?
6 multiplied by 1 equals 6
6 multiplied by 3 equals 18
6 multiplied by 5 equals 30
6 multiplied by 7 equals 42
6 multiplied by 9 equals 54
6 multiplied by 11 equals 66
The loop has finished
Input:
10
Output:
Which times table would you like?
10 multiplied by 1 equals 10
10 multiplied by 3 equals 30
10 multiplied by 5 equals 50
10 multiplied by 7 equals 70
10 multiplied by 9 equals 90
10 multiplied by 11 equals 110
The loop has finished
The number can be 0 or negative as well, and your program does not need to treat
those any differently. With 0 every product is 0, and with -3 the first
line reads -3 multiplied by 1 equals -3.
Ask the question with its own print, and read the answer with a bare
input() on the next line, rather than passing the question to input(...).
The question is part of the output that is checked here, so its spelling,
capital letters and punctuation count: it must read exactly
Which times table would you like?.
Make sure that you check for the following things:
while.while line has a condition.while line has a colon (:) at the end.while, and all of
it by the same amount. Never mix tabs and spaces in one file.input is wrapped in int(), or the number is multiplied as text.str() before it is joined onto text with a +.