My issue
why should I use for loop in this problem
My code
T=int(input())
x,y = map(int,input().split())
if x+y > 6 :
print("YES")
else:
print("no")
Problem Link: GDTURN Problem - CodeChef
why should I use for loop in this problem
T=int(input())
x,y = map(int,input().split())
if x+y > 6 :
print("YES")
else:
print("no")
Problem Link: GDTURN Problem - CodeChef
t = int(input())
for i in range(t):
x, y = map(int, input().split())
total = x + y
if total > 6:
print(“YES”)
else:
print(“NO”)
The reason you should use loop is you are answering for T number of testcases.
What’s the point of T in your program? (
)
You have to loop T times, get the input T times and print the output for each testcase.
you have to use loop because we are about to check " t "number of text cases. so that have to use a Loop.here we can use both the loops i.e,. While loop and For loop .we use while loop in the case where we don’t have an idea about number of iterations .
CODE using WHILE LOOP using C++:
while(t–)
{
int X,Y;
cin>>X>>Y;
if((X+Y)>6)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}
For loop is used. when we have an idea about number of iterations .
CODE using FOR LOOP using C++:
for(i=0;i<t;i++)
{
int X,Y;
cin>>X>>Y;
if((X+Y)>6)
{
cout<<“YES”<<endl;
}
else
{
cout<<“NO”<<endl;
}
}