Gorib_coder
Gorib_coder

Reputation: 45

Take integer Input with space and store the value in python

I am trying to solve the clock angle problem and there I had to take input like below:

Input

2
5 30
6 00

where The first line contains the number of test cases T . Each test case contains two integers h and m representing the time in an hour and minute format.

I am trying to take input like this

size=int(input())

for i in range(size):
    h,m=list(map(int,input().split(' ')))

but I'm unable to store the value for clock angle calculation as it's replacing the previous value.

Upvotes: 1

Views: 342

Answers (3)

Cosmos
Cosmos

Reputation: 392

Try this:

size = int(input())
angle = []
clock = []

for i in range(size):
    Inp = input().split(' ')
    clock.append(Inp) # store input clock
    hour, minute = int(Inp[0]), int(Inp[1])
    ans = abs((hour * 30 + minute * 0.5) - (minute * 6))
    angle.append(min(360 - ans, ans)) # store angle

print(clock)
print(angle)

Output hour = 2, minute = 2 and hour = 12, minute = 2:

[[2, 2], [12, 2]]
[49.0, 11.0]

Upvotes: 0

Prune
Prune

Reputation: 77837

You practically answered the question yourself: don't overwrite the first input with the second until you're done with it.

size=int(input())

for i in range(size):
    h,m=list(map(int,input().split(' ')))
    # Do you calculation here.
    hour_pos = h + m/60
    angle = ...
    print(angle)

Upvotes: 0

Mureinik
Mureinik

Reputation: 311188

You could declare a list to contain the inputs outside the loop and append to it in each iteration:

size=int(input())

clocks = []
for i in range(size):
    clocks.append(list(map(int,input().split(' '))))

Upvotes: 1

Related Questions