Code:
def string_to_number():
# Write your code here
for _ in range(int(input())):
s = input()
num = 0
for char in s:
num = num*10+(ord(char)-ord(“0”))
print(num)
string_to_number()
Error:
Additional info
Help me please, I do not understand what should i do here to solve this
It is first time that I see this kind of upload of photos.
Tried adding the mentioned variable and etc, but nothing.
After numerous tries found the BUG.
Copy from task:
Input Format
The first line contains a single integer, T, the number of test cases.
The following T lines each contain a single string, S, representing the number.
It seems that even if they ask to handle test cases code as in earlier lessons but You cannot do this, because if You handle the test cases the error stars showing up because they hid the test cases code after Your visible code lines. That means that we should not handle test cases because it is handled already.
Sad that I had to figure out this myself
Code that works:
def string_to_number(s):
# Write your code here
num = 0
for char in s:
num = num*10+(ord(char)-ord(“0”))
return num