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

4th Jun 2021, 4:11 PM
Diana Miranda
Diana Miranda - avatar
7 Respostas
+ 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)]
4th Jun 2021, 4:47 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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
4th Jun 2021, 4:50 PM
Lisa
Lisa - avatar
+ 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
4th Jun 2021, 4:17 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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]
4th Jun 2021, 4:30 PM
Lisa
Lisa - avatar
+ 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] """
4th Jun 2021, 5:58 PM
visph
visph - avatar
+ 1
Ok thanks for your help! I'm going to try it!
4th Jun 2021, 4:51 PM
Diana Miranda
Diana Miranda - avatar
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
4th Jun 2021, 4:33 PM
Diana Miranda
Diana Miranda - avatar