【问题标题】:How to make inputs not strings (python)如何使输入不是字符串(python)
【发布时间】:2022-11-12 01:10:31
【问题描述】:

我正在制作一个快速的问题解决器,它需要速度(输入)和时间(也是输入)而不是乘以它们以获得距离......问题是python认为输入是字符串,我如何让它们成为数字? ?

到目前为止,我的代码是:

py
import random

time = input("What is the time it took? (no label :: ")
speed = input("What was the speed?(no label :: ")
s = speed
t = time
distance = s * t
print(time)
print(speed)
print(distance)

【问题讨论】:

    标签: python string input


    【解决方案1】:

    您应该能够简单地将字符串输入转换为整数。执行以下操作将为您提供所需的输出。

    s = int(speed)
    t = int(time)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-03
      • 2016-03-05
      • 1970-01-01
      • 2018-12-07
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 2014-04-25
      相关资源
      最近更新 更多