Python Code Use (for loops) inside another for
loop (a nested loop) to do the following:
Print Hello 30 times followed by Bye 10 times. Do that whole thing
15 times. (for a total of 600 lines of output)
#Hint: First write the code that prints 30 "Hello" and then 10
"Bye". Think of that as two separate tasks, each of which requires
its own for loop. THEN, once you get that working, put all of that
inside ANOTHER loop that repeats 15 times.
main is required.
# main
if __name__ == "__main__":
# outer loop runs 15 times
for _ in range(15):
# this loop runs 30 times
for _ in range(30):
print("Hello")
# this loop runs 10 times
for _ in range(10):
print("Bye")
if you have any doubt, feel free to ask in the comments.
Get Answers For Free
Most questions answered within 1 hours.