0
Put 3 values in input with for
I have this code n= int(input ()) place= [float(input()) for _ in range(n)] But I want to put 3 values in the input of place! I try with many ways but can't find a solution
7 Answers
+ 1
I think this should work:
n = int(input())
place = []
for i in range(n):
place.append(float(input())
But be aware that you need to enter all values at the beginning.
n = 5 means enter at first n and after that 4 values.
Edit:
Works also:
place = [float(input()) for i in range(n)]
+ 3
Denise RoĂberg the input in the list comprehension as in the question should work pretty much the same as the explicit for loop
+ 2
a = int(input())
b = int(input())
c = int(input())
To get it work on sololearn you need to enter the values in this way
4 [enter]
3 [enter]
2 [submit]
Now a = 4, b = 3 and c = 2
+ 2
Your code looks fine. Maybe it's just the way you tried to input.
Suppose you want to input 2 floats (e.g. 1.1 and 2.2), then you would need to type
2 [enter, this is n]
1.1 [enter, the first value for place]
2.2 [submit, it's the 2nd value for place]
+ 2
place = [float(v) for _ in range(int(input())) for v in input().split()]
print(place)
"""
for given input:
4
1.1 1.2
2.1 2.2
3.1 3.2
4.1 4.2
output:
[1.1, 1.2, 2.1, 2.2, 3.1, 3.2, 4.1, 4.2]
"""
+ 1
Ok thanks for your help! I'm going to try it!
0
Yes! But I want to put the both floats Inthe same line and if I say 4, put 4 lines with 2 floats each one