【问题标题】:Decimal number list input十进制数列表输入
【发布时间】:2019-04-29 10:20:36
【问题描述】:

我还想输入十进制数字。我试过float,但没用。

这是我需要更正的代码:

a = input()
b = input()
list1 = list(map(int, a.split()))
list2 = list(map(int, b.split()))
garums1 = len(list1)
garums2 = len(list2)
summa=0
for i in range(len(list1)):
    if garums1==garums2:
        summa=list1[i]/list2[i]
        print(round(summa,1), end=" ")

代码有效

1 2 3 4
2 3 4 5
0.5 0.7 0.8 0.8 

也需要这样的东西

1.23 4.1 51.3 44
2 4.1 4 5
0.6 1.0 12.8 8.8

【问题讨论】:

    标签: python python-3.x list input decimal


    【解决方案1】:

    只需将映射从int 更改为float

    a = input()
    b = input()
    list1 = list(map(float, a.split()))
    list2 = list(map(float, b.split()))
    garums1 = len(list1)
    garums2 = len(list2)
    summa=0
    for i in range(len(list1)):
        if garums1==garums2:
            summa=list1[i]/list2[i]
            print(round(summa,1), end=" ")
    

    【讨论】:

      【解决方案2】:

      对于list1list2,试试:

      list1 = [float(i) for i in a.split()]
      list2 = [float(i) for i in b.split()]
      

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-20
        • 2019-09-02
        • 2019-08-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多