Discuss / Python / 大家帮我看看呢,我实在是不知道问题出在哪

大家帮我看看呢,我实在是不知道问题出在哪

Topic source

nightmarelink

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

name=input('please enter your name') print('Hello',name) s1=input('How many points did you get last term') s2=input('How many points did you get this term') print(r'''wa o you have done a good job your score is increasing%.1f%%'''%(s2-s1)/s1)

你这个s1,s2的运算完成过后是小数,要乘以100再加个百分号才对了,应该是这个问题吧?

nightmarelink

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

不对,还是有问题,报错

nightmarelink

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

我在学习条件判断章节的时候了解到input返回的是str类型数据,不能和数字直接比较。我突发灵感,既然不能比较那一定就不能计算。所有我返回到这里来,调整了一下我之前的问题代码,结果顺利运行。一块石头终于落下,我很开心。以下是修改之后的代码。

name=input('please enter your name') print('Hello',name) s1=input('How many points did you get last term') s2=input('How many points did you get this term') n=int(s1) m=int(s2) c=(m-n)/n print(r'''wa o you have done a good job your score is increasing%.1f%%'''%c)

Aisallin

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

s1=int(input('How many points did you get last term')) s2=int(input('How many points did you get this term')) 这样就可以计算了


  • 1

Reply