Reputation: 15
t = int (input())
for i in range(t):
A,B = map(int,input().split())
print(int('Case #%d:' + (A+B) %t))
This code gets number of times(t) the loop is going to repeat, gets two numbers from the user and prints out the sum of two numbers
however,
I get a type error that says "must be str not int" how can i fix this?
Upvotes: 1
Views: 51
Reputation: 15
cases = int(input())
for i in range(cases):
a,b = map(int, input().split())
ans = a + b
print("Case #%s: %s"%(i+1, ans ))
Thanks for the contribution! so I tried this way and it worked as well!
Upvotes: 0
Reputation: 91
try this code
t = int (input())
for i in range(t):
A,B = map(int,input().split())
print('Case #{case}:{sum}'.format(case = i,sum= A+B))
Upvotes: 1
Reputation: 3961
You cannot make the print statement content into an int, but you can do this instead:
t = int(input())
for i in range(t):
res = input("input string")
res = res.split()
print(res)
A, B = map(int, res)
print('Case #%d:' %t + str(A+B))
Returning for t = 2, and res = 2, 3 and 4, 5:
input string2 3
['2', '3']
Case #2:5
input string4 5
['4', '5']
Case #2:9
Upvotes: 2
Reputation: 669
Your print statement is wrong, use this:
t = int (input())
for i in range(t):
A,B = map(int,input().split())
print(f'Case #{i}: {A+B}')
Upvotes: 2