首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何纠正未定义TypeError字符串

如何纠正未定义TypeError字符串
EN

Stack Overflow用户
提问于 2016-06-09 03:10:49
回答 2查看 13.6K关注 0票数 4

我们必须询问用户在一个月内使用了多少分钟,并将其乘以0.10,以获得他们在分钟上花费的时间。

代码:

代码语言:javascript
运行
复制
mins = input("How many minutes have you used this month? ")
minsprice = float(mins)*0.10
print ("You have used",round(mins,2),"GBP worth of minutes this month.")

它返回以下错误:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "C:\Users\User\Downloads\assessment.py", line 23, in 
    print ("You have used",float(round(mins,2)),"GBP worth of minutes this month.")
TypeError: type str doesn't define __round__ method
EN

Stack Overflow用户

发布于 2021-03-01 14:42:43

我想你打错了。你写mins。它应该是minsprice最后一行。这就是错误发生的原因。试试这个

代码语言:javascript
运行
复制
mins = input("How many minutes have you used this month? ")
    minsprice = float(mins)*0.10
    print ("You have used",round(minsprice,2),"GBP worth of minutes this month.")
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37710950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档