137k views
3 votes
6.12 Nested Increments Write a program for spiritual lumberjacks who want to show their appreciation for each tree they 'kill' by celebrating its years of life. Ask the lumberjack how many trees he wants to cut. Verify you got the number correctly by printing it to output. Write a loop that iterates over all the trees the lumberjack wants to cut down. Print the tree number to the screen to make sure your loop is working correctly. Query the lumber jack for how many rings are in this tree and print this number to make sure you got the correct number of rings. Write an inner loop that iterates over the years of the tree. Print each year to make sure you are iterating correctly and hitting each year that it lived. Change the necessary print statements and to match the correct formatting from the output examples.

User Nyla
by
7.5k points

1 Answer

5 votes

Answer:

trees_to_cut = int(input("How many trees do you wants to cut? "))

print(str(trees_to_cut) + " tree(s) will be cut.")

for i in range(trees_to_cut):

print("Tree #" + str(i))

rings = int(input("How many rings in tree " + str(i) + "? "))

print("There are " + str(rings) + " ring(s) in this tree.")

for j in range(rings):

print("Celebrating tree #" + str(i) + "'s " + str(j+1) + ". birthday.")

Step-by-step explanation:

*The code is in Python.

Ask the user to enter the number of trees to cut

Print this number

Create a for loop that iterates for each tree

Inside the loop:

Print the tree number. Ask the user to enter the number of rings. Print the number of rings. Create another for loop that iterates for each ring. Inside the inner loop, print the celebrating message for each birthday of the tree

User Anastasia Black
by
8.5k points