Feb-24-2021, 03:47 PM
This code ends by printing 4:
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)":
import sys for i in range(10): if i == 5: sys.exit(0) print(i)When I enter sum_two(3.5,6), the following prints "SystemExit" and then "UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)":
print() print('The function sum_two(a,b) will sum integers a and b.') print('If sum is between 15 to 20 then output will be 20.') def sum_two(a,b): if type(a) != int or type(b) != int: print('a and b must both be integers.') sys.exit() if a+b > 15 and a+b < 20: sum = 20 else: sum = a+b return sumWhy doesn't the latter give me a clean exit like the former? Thanks!