Advertisement
Guest User

Repeating step problem in nested function restart

a guest
Oct 7th, 2017
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. # Defining 'i' and the 'numbers' empty list
  2. i = 0
  3. numbers = []
  4.  
  5. print("\n")
  6.  
  7. # While is is less than 6, it adds the index number to the end of the 'numbers' list.
  8. def numbering(i, high, jump):
  9.     while i < high:
  10.         print(f"At the top i is {i}")
  11.         numbers.append(i)
  12.    
  13.         i = i + jump
  14.         print("The list 'numbers' is now: ", numbers)
  15.         print(f"At the bottom i is {i}\n")
  16.  
  17. print("Now we will define a list consisting of a sequence of integers")
  18.  
  19. # Asking for variables
  20. def ask():
  21.     bottom = int(input("Add the lowest element in the list: "))
  22.     top = int(input("Add the highest element in the list: "))
  23.     if top < bottom:
  24.         print("\nThe highest element needs to be higher than the lowest!\n")
  25.         ask()
  26.     step = int(input("Add the step by which the list increments: "))
  27.     return(bottom, top, step)
  28.  
  29. bottom, top, step = ask()
  30. print("\n")
  31.  
  32. # Running the function
  33. numbering(bottom, top + 1, step)
  34.  
  35. warning = "!!!   Notice how the very last number did not go into the list   !!!"
  36.  
  37. print("." * len(warning))
  38. print(warning)
  39. print("." * len(warning))
  40. print("\n")
  41.  
  42. # Prints all the numbers in the 'numbers' list
  43. print("The numbers in the 'numbers' list are: ")
  44. for num in numbers:
  45.     print(num)
  46.  
  47. print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement