Python split related error

Asked 2 years ago, Updated 2 years ago, 90 views

def cal(a,b):
   print(a,'+',b,'=',a+b)
   print(a,'-',b,'=',a-b)
   print(a,'*',b,'=',a*b)
   print(a,'/',b,'=',a/b)
n=int (input ('two integer inputs:')).spilt()
cal(n)

If you create a function like this and enter two integers, the error 'invalid literal for int() with base 10:' appears. Why is there such an error even though I entered an integer?

python error split

2022-09-20 17:02

1 Answers

It's because I split the int.

def cal(a,b):
    print(a,'+',b,'=',a+b)
    print(a,'-',b,'=',a-b)
    print(a,'*',b,'=',a*b)
    print(a,'/',b,'=',a/b)
n=list (map(int, input('Enter two integers:')).split()))
cal(n[0], n[1])


2022-09-20 17:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.