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 numbershowever,I get a type error that says "must be str not int" how can i fix this?
4 Réponses :
Votre déclaration d'impression est erronée, utilisez ceci:
t = int (input()) for i in range(t): A,B = map(int,input().split()) print(f'Case #{i}: {A+B}')
Vous ne pouvez pas transformer le contenu de l'instruction d'impression en un entier, mais vous pouvez le faire à la place:
input string2 3 ['2', '3'] Case #2:5 input string4 5 ['4', '5'] Case #2:9
Retour pour t = 2, et res = 2, 3 et 4, 5:
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))
essayez ce 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))
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!
Je ne sais pas ce que ce
print (int ('Case #% d:' + (A + B)% t))
est censé faireVeuillez mettre à jour votre question avec le suivi complet des erreurs.