1

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.

1

3 Answers 3

1

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(' '))))
Sign up to request clarification or add additional context in comments.

Comments

0

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]

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.