我借助互联网上的资源和 Allen B.Downey 的 Think Python 书籍开始学习 Python。我遇到一个问题,提到分钟到秒的转换。但是,我面临一个错误。变量 min_1 的类型。
我也尝试将变量转换为 int ,这给出了不同的错误。请指导!
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)
我尝试了上面共享的解决方案,但随后出现了这个错误:
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'