Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Take two integers from the user'
- def get_num(prompt='Enter integer: ', fail_msg="Not a valid integer."):
- while True:
- try:
- return int(input(prompt))
- except ValueError:
- print(fail_msg)
- 'Save the lower number as x, Save the largest integer as y'
- x, y = sorted((get_num(), get_num()))
- 'Write a loop that counts from x to y by twos.'
- for counter in range(x, y + 1, 2):
- 'Print out the values of that loop - ???means counter??? - using the Print function in Python'
- print(f'counter: {counter}')
- 'Write another loop that adds x and y, and saves the value as Z'
- '???Do not understand the requirement, guess it means add values from x to y'
- z = 0 # starter value for z
- for idx in range(x, y + 1): # count from x to y and add values
- z += idx # increment current value referenced by current count
- 'Print out the values of Z using the Print function in Python.'
- print(f'index: {idx}, z is now: {z}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement