python - 百分比计算不起作用

标签 python calculator percentage

mark=input("Please enter the mark you received for the test:")
total=input("Please enter the mark the test was out of:")

percentage=(mark*100/total)

print("Your percentage is:"),percentage,"%"

当我在 python 3.3.2 mac 中运行它时出现了这个错误。

Traceback (most recent call last):
  File "/Users/user1/Desktop/Percentage2.py", line 4, in <module>
    percentage=(mark/total*100)
TypeError: unsupported operand type(s) for /: 'str' and 'str'

我该如何解决?

最佳答案

percentage=(float(mark)*100/float(total))

print("Your percentage is: ",percentage,"%", sep='')

关于python - 百分比计算不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18251239/

相关文章:

python - 如何使算法更快?

python - Flask URL 路由

java - BMI计算器错误

css - @media 不适用于宽度小于 1024px 的情况

python - 可疑行为 - 在 Python 3.4.1 中 str 不可调用返回 "".join(list(map(str,reversed(result))))

python - 避免 subprocess.Popen 的 stdout 管道堵塞并卡住子进程

java计算器-清除累加器

C中的更改计算程序

css - 为什么网格间隙中的百分比值会在 CSS 网格中造成溢出?

使用小数类型的 C# 百分比计算会导致问题