Home > OS >  Adding a print out message to count in loop (Python)
Adding a print out message to count in loop (Python)

Time:05-05

With 'range' is it possible to add a print out message when the count hits a number in the range:

Starting with this:

for number in range(0,11):

   print(number)

CodePudding user response:

for number in range(0, 11):
    if number == 6: #the number in the range
        print(f'Number has hit {number}')

CodePudding user response:

Turn that question into pseudocode. Let's say 7 is your target number.

for number in range between 0,11
if number equals my target number
print out that number

With that rational, it might be something like this:

for number in range(0,11):
 if(number == 7):   
   print("here is the target number: ", number)
  • Related