Python Forum
While loop that needs to count up
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop that needs to count up
#1
The code works as it should with one exception, I can't seem to figure it out.

User-inputs a number and then I need the program to print 1 : text then 2 : text until the number that was entered is reach. So input of 2 would result in 1 : text then newline 2 : text

This is the code I have now for it.
def shampoo_instructions(num_cycles):
    if num_cycles < 1:
        print('Too few')
    elif num_cycles > 4:
        print('Too many')
    else:
        i = num_cycles
        while i <+ 4:
            print(i,': Lather and rinse.')
            i += 1
        print('Done.')
shampoo_instructions(2) 
OUTPUT
2 : Lather and rinse.
3 : Lather and rinse.
Done.
 
Reply


Messages In This Thread
While loop that needs to count up - by ImLearningPython - Dec-16-2018, 11:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to implement loop count zukochew 3 2,687 Jul-25-2018, 06:23 PM
Last Post: ichabod801
  Count Letters in a Sentence (without using the Count Function) bhill 3 5,250 Jun-19-2018, 02:52 AM
Last Post: bhill

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020