0

Could you tell me how to read all the lines from the input?

I'm trying to get information using:

data = input()

Input:

5
1
22:13:56-22:13:55
1
00:00:00-23:59:59
1
23:59:59-00:00:00
2
00:00:00-23:59:59
00:00:00-23:59:59
2
13:44:59-13:44:59
13:45:00-13:45:00

But the data list contains only '5'

Tivasic
  • 25
  • 4

2 Answers2

1

You can read the input in loop and append it to some string. Example:

data = ''
while True:
    line = input()
    if line == 'q':
        break
    data += line
maciek97x
  • 2,251
  • 2
  • 10
  • 21
0

for the sake of understanding added input statement also.

Code snippet:

no_of_testcases=int(input("Enter the no_of_testcase: "))
data=[]
for i in range(no_of_testcases):
    n=int(input("Enter how many time interval you wanted to enter: "))
    for j in range(n):
        data.append(input("Interval: "))

print(data)

Output:

Enter the no_of_testcase: 5
Enter how many time interval you wanted to enter: 1
Interval: 22:13:56-22:13:55
Enter how many time interval you wanted to enter: 1
Interval: 00:00:00-23:59:59
Enter how many time interval you wanted to enter: 1
Interval: 23:59:59-00:00:00
Enter how many time interval you wanted to enter: 2
Interval: 00:00:00-23:59:59
Interval: 00:00:00-23:59:59
Enter how many time interval you wanted to enter: 2
Interval: 13:44:59-13:44:59
Interval: 13:45:00-13:45:00
['22:13:56-22:13:55', '00:00:00-23:59:59', '23:59:59-00:00:00', '00:00:00-23:59:59', '00:00:00-23:59:59', '13:44:59-13:44:59', '13:45:00-13:45:00']
Yash Mehta
  • 2,025
  • 3
  • 9
  • 20
  • Is it possible for me to copy this entire structure and read it as a whole, that is, without entering it separately? – Tivasic Jan 27 '23 at 12:18
  • if it is in file than the answer is given by the stack member.. but if it is in console i don't think so we can do that..! @Tivasic – Yash Mehta Jan 27 '23 at 12:21