@ems314
how can you say your code works fine on interpreter?
I referred your last attempt and saw this code, and it seems your logic in dsc() is correct but…
t = input ()
def dsc(t):
used = ""
for lets in t:
if lets not in used:
used = used + lets
print len(used)
First observe problem what the problem says:
Input:
First line contains T, number of testcases. Each testcase consists of a single string in one line. Each character of the string will be a small alphabet(ie. ‘a’ to ‘z’).
that means, first input contains an integer t, representing number of test cases,
so you have to take that value into consideration ,
t=int(raw_input())
int() is used to typecast string input into integer.
Then you have to take string for operation as input for t times as t represents number of test cases so,
for num in range(t):
string=input()
These two steps are mandatory now you may implement any logic…
Considering your logic…
First let me tell you what mistake you committed,
Step 1: You took an input t
Step 2: you defined a function dsc() and implemented your logic inside your function… and end…
But this is not the end, if you have defined a function, you have to call the function by passing the required arguments,
In your case, first you have to take no. of test cases as input, let test is that variable so just add this line above all lines,
test=int(raw_input())
Then you took t as string input but you have to take that input for test times so it should be,
for num in range(test):
t = raw_input()
then defining function and implementing code in function is good, but all this you were coding above function definition were the part of main function so cut paste dsc() at the top of your program, thus your code becomes like this,
def dsc(t):
used = ""
for lets in t:
if lets not in used:
used = used + lets
print len(used)
test=int(raw_input())
for num in range(test):
t = raw_input()
now everything is set, just you have to call the function, which is done as,
dsc(t)
so add this piece in main function after taking t as string input, inside for loop…
So your final code becomes…
#dsc()
def dsc(t):
used = ""
for lets in t:
if lets not in used:
used = used + lets
print len(used)
# main()
test=int(raw_input())
for num in range(test):
t = raw_input()
dsc(t)
Check this Submission link :http://www.codechef.com/viewsolution/5501541
Hope you have understood the basic concept…
Try this your self…