Discuss / Python / 请问一下为什么要用int 还有为什么回车运行完程序窗口就自动关闭了啊 结果都看不到

请问一下为什么要用int 还有为什么回车运行完程序窗口就自动关闭了啊 结果都看不到

Topic source

如下

a = int(input('请输入去年成绩:'))
b = int(input('请输入今年成绩:'))
c = ((b-a)/a)*100
print("成绩提升:%.1f%%" %(c))

这个是一开始没成功,然后查了一下好像用了int(input())才改的 一开始没用int 直接用的input 然后就显示 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for -: 'str' and 'str' 请问一下: 第一 为什么要用int再input? 第二 这个是逐行在命令符里Python运行的 要是保存成.py然后回车 运行之后窗口就自动关闭了 这个是为什么? 零基础小白TAT

Chenhr_94

#2 Created at ... [Delete] [Delete and Lock User]

第一问:直接input的话是字符串,加上int才能变成一个数 第二问:估计你这个是另外弹出的窗口运行的吧?

谢谢楼上 我确实是回车直接运行的 第一个问题也懂了 哈哈哈


  • 1

Reply