TypeError:在 JupyterLite 上运行代码时,* 不支持的操作数类型:“Future”和“int”

问题描述 投票:0回答:3

Received error on converting min_1 variable to int(min_1) in line 6

我借助互联网上的资源和 Allen B.Downey 的 Think Python 书籍开始学习 Python。我遇到一个问题,提到分钟到秒的转换。但是,我面临一个错误。变量 min_1 的类型。

我也尝试将变量转换为 int ,这给出了不同的错误。请指导!

python-3.x
3个回答
0
投票

请记住,

input
的结果是一个字符串。因此请尝试:

min_1 = int(input("How many minutes?"))

然后

min_to_sec = min_1 * 60 

应该可以正常工作


0
投票

input()
的返回类型是
string
,需要根据您的输入将其类型转换为
int
float

下面的代码工作正常。

min_1 = int(input("How many minutes"))
sec = int(input("How many seconds"))

min_to_sec = min_1 * 60
total_time = min_to_sec + sec

print("Total time: ", total_time)


0
投票

我尝试了上面共享的解决方案,但随后出现了这个错误:

TypeError                                 Traceback (most recent call last)
Cell In[10], line 1
----> 1 min_1 = int(input("How many minutes"))
      2 sec = int(input("How many seconds"))
      4 min_to_sec = min_1 * 60

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'PyodideFuture'
© www.soinside.com 2019 - 2024. All rights reserved.