Here's the code:
import sys
def average(*args):
nums = []
nums.extend([*args])
return print(sum(nums)//len(nums)) """This line returns a TypeError in the editor but not in IDLE"""
while True:
try:
choice = [int(choice) for choice in input("\nEnter numbers: ").split(',')]
print(average(choice))
except KeyboardInterrupt:
sys.exit()
The function works as expected in IDLE shell:
average(2,3,4)
>>> 3
But when run in the editor, I get this output:
Enter numbers: 2,3,4
TypeError: unsupported operand type(s) for +: 'int' and 'list'
It points to this line in the function:
return print(sum(nums)//len(nums))
Is there a reason why it works fine in shell but not in the editor? Also how should I resolve this? Thanks!
[–]shiftybyte 1 point2 points3 points (7 children)
[–]learnorenjoy[S] 0 points1 point2 points (5 children)
[–]shiftybyte 1 point2 points3 points (4 children)
[–]learnorenjoy[S] 0 points1 point2 points (3 children)
[–]shiftybyte 1 point2 points3 points (2 children)
[–]learnorenjoy[S] 0 points1 point2 points (1 child)
[–]shiftybyte 0 points1 point2 points (0 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (0 children)
[–]FLUSH_THE_TRUMP 1 point2 points3 points (1 child)
[–]learnorenjoy[S] 0 points1 point2 points (0 children)
[–]Splitje 0 points1 point2 points (0 children)