0% found this document useful (0 votes)
10 views2 pages

Python Function for Question Mark Validation

The document contains a Python function named 'questionmark' that checks if there are two digits in a string whose sum equals 10, with exactly three '?' characters between them. If the conditions are met, it returns 'true'; otherwise, it returns 'false'. Example inputs and outputs are provided to demonstrate the function's behavior.

Uploaded by

kdiljeet814
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Python Function for Question Mark Validation

The document contains a Python function named 'questionmark' that checks if there are two digits in a string whose sum equals 10, with exactly three '?' characters between them. If the conditions are met, it returns 'true'; otherwise, it returns 'false'. Example inputs and outputs are provided to demonstrate the function's behavior.

Uploaded by

kdiljeet814
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASSIGNMENT:-

defquestionmark(s):

digits=[(i,int(ch))fori,chinenumerate(s)[Link]()] if

len(digits) < 2:

return"false"

found= False

foriinrange(len(digits)):

forjinrange(i+1,len(digits)):

idx1,d1=digits[i]

idx2,d2=digits[j]

if d1 + d2 == 10:

found= True

between=s[idx1+1:idx2] if

[Link]('?') != 3:

return"false"

return"true"iffoundelse"false"

ex1= questionmark("aa6?9")

print(f"outputforinputaa6?9is:{ex1}")

ex2=questionmark("arrb6???4xxb15???eece5")

print(f"output for input aa6?9 is :{ex2}")

#enterinputininp"acc?7??sss?3rr1??????5"tocheckweatherthiscodeisworkproperlyornot. inp =

input("input is: ")

result=questionmark(inp)

print(f"inputstringis:{inp},output:{result}")

OUTPUT:--outputforinputaa6?9is:false

outputforinputarrb6???4xxb15???eece5is:true input

is:acc?7??sss?3rr1?? ????5

inputstringis:acc?7??sss?3rr1??????5,output:true

You might also like