samedi 1 septembre 2018

Python code to check if a input string can be written with a single row of keyboard(eg:potter,flash)

Write a Python code to check if the given word can be typed using just a single row of the keyboard. (e.g. POTTER, EQUITY). Print 'Yes' if the letters of the word are from a single row and print 'No' otherwise.

PLEASE DON'T USE CONCEPTS OTHER THAN STRINGS OR WHATEVER I HAVE USED

Here is my code (not getting desired output)

row1='qwertyuiop'
row2='asdfghjkl'
row3='zxcvbnm'
i=0
j=0
status='no'
st=input('enter a string : ')
if st[0] in row1:
    while(i<len(st)):
        while(j<len(row1)):
            if(st[i]==row1[j]):
                status='yes'
                i+=1
                j=0

            elif(j==(len(st)-1)):
                 status='no'
                 break
            else:
                j+=1
    j=0
    i=0

elif st[0] in row2:
     while(i<len(st)):
        while(j<len(row2)):
            if(st[i]==row2[j]):
                status='yes'
                i+=1
                j=0

            elif(j==(len(st)-1)):
                 status='no'
                 break
            else:
                j+=1
    j=0
    i=0
else: 
    while(i<len(st)):
        while(j<len(row3)):
            if(st[i]==row3[j]):
                status='yes'
                i+=1
                j=0

            elif(j==(len(st)-1)):
                 status='no'
                 break
            else:
                j+=1    ``
print(status)

Aucun commentaire:

Enregistrer un commentaire