+ 1

Help

numbers = int(input()) #(2+4) = 6 print(numbers) >>> numbers = int(input()) ValueError: invalid literal for int() with base 10: '(2+4)' lst = [(2+4),(5*2),(6-5)] for i in lst: print(i) >>> 6 10 1

28th Feb 2022, 8:12 PM
CodeStory
CodeStory - avatar
3 Respostas
+ 6
CodeStory Take input as string and remove first and last bracket. Then use loop and eval function to calculate like this: numbers = input() #(2+4) = 6 print(numbers) list1 = (numbers[1:-1]).split(',') for k in list1: print (eval(k))
28th Feb 2022, 8:26 PM
A͢J
A͢J - avatar
+ 4
CodeStory [(2+4) is a not an integer value so you cannot cast with int.
28th Feb 2022, 8:18 PM
A͢J
A͢J - avatar
+ 2
Thank you very much, good luck to you!! 👍👍👍
28th Feb 2022, 8:30 PM
CodeStory
CodeStory - avatar