Advertisement
timber101

Loops

Nov 6th, 2022
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #  don't forget to un comment ( remove the pairs of """ )
  2. Colin
  3. # forever loop
  4. """
  5. while True:
  6.    print("hello")
  7.    input("")
  8. """    
  9. # condition controlled loop
  10. # keep going until "Q" is pressed
  11. """
  12. option = "" # sentinal value
  13. while option != "Q":
  14.    print("Colin was here")
  15.    option = input("Enter a letter or Q to quit ")
  16.    print("you pressed >>",option)
  17.  
  18. print("loop exited")
  19. """
  20.  
  21. # count controlled loop
  22. # know how many times our loop will run
  23. # len(variable_name) => integer
  24.  
  25. # print number 1 - 5 inclusive
  26.  
  27. num =1
  28. for i in range(5):
  29.     print(num)
  30.     num= num+1
  31.     print("line29",num)
  32.    
  33. # print out the letters in a word one by one
  34. """
  35. my_word = input("Let's have a word >>")
  36.  
  37. for i in range(len(my_word)):
  38.    print(i)
  39.    print(my_word[i])
  40.    
  41. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement