Advertisement
gruntfutuk

numberstuff

Jun 22nd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. 'Take two integers from the user'
  2. def get_num(prompt='Enter integer: ', fail_msg="Not a valid integer."):
  3.     while True:
  4.         try:
  5.             return int(input(prompt))
  6.         except ValueError:
  7.             print(fail_msg)
  8.  
  9. 'Save the lower number as x, Save the largest integer as y'          
  10. x, y = sorted((get_num(), get_num()))
  11.  
  12. 'Write a loop that counts from x to y by twos.'
  13. for counter in range(x, y + 1, 2):
  14.     'Print out the values of that loop - ???means counter??? - using the Print function in Python'
  15.     print(f'counter: {counter}')
  16.    
  17. 'Write another loop that adds x and y, and saves the value as Z'
  18. '???Do not understand the requirement, guess it means add values from x to y'
  19. z = 0 # starter value for z
  20. for idx in range(x, y + 1):  # count from x to y and add values
  21.     z += idx # increment current value referenced by current count
  22.     'Print out the values of Z using the Print function in Python.'
  23.     print(f'index: {idx}, z is now: {z}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement