十进制数字列表inpu

2024-09-28 19:00:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我还想输入十进制数。我试过用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


Tags: 代码inmapforinputlenfloatlist
2条回答

只需将映射从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=" ")

对于list1list2,请尝试:

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

希望这有帮助

相关问题 更多 >