74.1k views
4 votes
Write code that prints: ready! firstnumber ___________ 2 1 go! Your code should contain a for loop. Print a newline after each number and after each line of code. If the input is 3, the output is: ready! 3 2 1 go!

1 Answer

2 votes

Final answer:

The student must write code that prints a countdown from an input number to 1, followed by "go!" This is done using a for loop that decrements each iteration and prints each number on a new line.

Step-by-step explanation:

The task is to construct code that counts down from a provided initial number to 1, and then prints "go!". The countdown should be prefaced by "ready!". To achieve this, a for loop is employed in the code. This loop will decrement from the input number down to 1. After the loop completes, "go!" is printed to signify the end of the countdown.

Here's an example of what the code in Python might look like:

number = int(input("Enter the first number: "))
print("ready!")
for i in range(number, 0, -1):
print(i)
print("go!")

In this example, the input function is used to capture the initial number for the countdown. The for loop then prints each number per iteration until it reaches 1. Following the loop, the word "go!" is outputted, completing the countdown sequence.

User Rabejens
by
7.0k points