python之报错ValueError:invalid literal for int() with base10

s1 = input("input a coordinate:")
s2 = input("input another coordinate:")
s3 = int(s1[0]) * int(s2[0])
print(s3)

运行后输入分别输入两个坐标,如图所示:
在这里插入图片描述
出现错误ValueError:invalid literal for int() with base10:’(’

原因:有时候需要用int()函数转换字符串为整型,但是切记int()只能转化由纯数字组成的字符串。

解决方案:
在这里插入图片描述

posted @ 2021-04-07 10:01  门前塘  阅读(1)  评论(0)    收藏  举报  来源