Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #This is Example 1-5
  2.  
  3. '''
  4.  
  5. Here we define a list of fruits
  6.  
  7. '''
  8.  
  9. fruits=['Peach', 'Grapes', 'Cherry', 'Orange']
  10.  
  11. #Here we print the list of fruits
  12.  
  13. print('Printing the list of fruits:')
  14.  
  15. for index in range(len(fruits)):
  16.  
  17. print(fruits[index], end=' ')
  18.  
  19. #Here we print the line break
  20.  
  21. print()
  22.  
  23. #Here we define variable stop
  24.  
  25. stop=20
  26.  
  27. #Here we use range so that the start is 0, step is 1 and the limit is defined
  28.  
  29. #by the value of variable stop
  30.  
  31. for number in range(stop):
  32.  
  33. print(str(number) + ' ', end="");
  34.  
  35. print()
  36.  
  37. #Here we define variable start
  38.  
  39. start=-10
  40.  
  41. #Here we use range so that the start is define by the value of variable start
  42.  
  43. #and stop is defined by the value of variable stop. The step is default, 1.
  44.  
  45. for number in range(start, stop):
  46.  
  47. print(str(number)+' ', end="");
  48.  
  49. print()
  50.  
  51. #Here we define variable step
  52.  
  53. step=3
  54.  
  55. stop=10
  56.  
  57. #Here we use range so that the start is define by the value of variable start
  58.  
  59. #and stop is defined by the value of variable stop. The step is defined by the
  60.  
  61. #value of variable step.
  62.  
  63. for number in range(start, stop, step):
  64.  
  65. print(str(number)+' ', end="");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement