Preceding Alphabets

 Coding Problem Keys 

 Preceding Alphabets 

 Problem Statement 

The program must accept a string S and an alphabet CH as the input. Then the program must print only the alphabets in S which occur before CH in the alphabetical order (from A to Z or a to z). CH can be in upper or lower case but the comparison must be case in-sensitive.

 Boundary Condition(s) 

2 <= Length of S <= 1000

 Input Format 

The first line contains string S.
The second line contains CH.

 Output Format 

The first line contains only the alphabets in S which occurs before CH in the alphabetical order.

 Example Input/Output 1 

 Input 

Breaking News
K

 Output 

Beaige

 Explanation 

Only Beaige are before K or k in the alphabetic order.

 Example Input/Output 2 

 Input 

my LITTLEprinCESS
p

 Output 

mLILEinCE

 Note: Max Execution Time Limit: 500 millisecs 

 Solution 

 Programming Language: Python 3 Language 

l=input().strip()
k=input().strip().lower()
s='abcdefghijklmnopqrstuvwxyz';j=0
for i in range(len(s)):
    if s[i]==k:
        j=i
        break
for i in l:
    if i.lower() in s[:j]:
        print(i,end="")

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Highly Profitable Months

Flowchart Logic 047

Desktop Products

Find Maxima/Minima

Matrix Print Excluding Border Elements

Words Starting with Upper Case

Occurrences of Sub in Parent