[英]Floating point not iterable python
I wanted to store floating point values in a list iteratively but it says floating point not iterable even if the iteration value was integer我想迭代地将浮点值存储在列表中,但它表示即使迭代值是整数,浮点数也不可迭代
n=int(input('Please enter value of N: '));
for i in range(n):
x=list(float,input('Please enter the values of X'+str(i)+': '));
You need to cast your input to float using float(input(...))
and then append it to a list, also you do not need a semicolon ;
您需要使用float(input(...))
将输入转换为 float ,然后将其附加到列表中,您也不需要分号;
in python在蟒蛇
n=int(input('Please enter value of N: '))
x = []
for i in range(n):
x.append(float(input('Please enter the values of X'+str(i)+': ')))
print(x)
The output will be.输出将是。
Please enter value of N: 3
Please enter the values of X0: 1
Please enter the values of X1: 2
Please enter the values of X2: 3
[1.0, 2.0, 3.0]
You can try;你可以试试;
n = int(input('Value for n: '))
lst = [float(input(f'Value for {x}: ')) for x in range(n)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.