The question I was solving is Room Allocation,on codechef but i get a Value Error and I try to fix it but i dont get it.
import math
t=int(input())
for i in range(t):
n=int(input())
s=0
for j in range(n):
a=int(input())
half=a//2
s=s+half
print(s)
@sakshya01
plzz send the problem link.
You mean Room Allocation problem?
It’s impossible to know what it happening in your code due you are using Python and you are sharing it without indentation.
My guess is that you are doing this:
import math
t=int(input())
for i in range(t):
n=int(input())
s=0
for j in range(n):
a=int(input())
half=a//2
s=s+half
print(s)
Input values. You are receiving the A array like if it was an only integer. That throws a ValueError because your int() cast is trying to cast whitespaces into integers.
You are doing this:
a = int(input())
When you should be doing this:
a = list(map(int, input().split())
In Python, when you get the single line of integers, you should use input().split() to get the complete list. So your code should be:
import math
t=int(input())
for i in range(t):
n=int(input())
a = list(map(int, input().split())
s=0
for j in range(n):
# Choose a way to access your list
half= ( ... )//2
s=s+half
print(s)
That will solve your Value Error problem.
1 Like
Thanks @ulisesaugusto1 Thankyou for helping me out
1 Like