简体   繁体   中英

How to write a program in python which prints the fist letter of every word of the input string without using built-in fuctions?

sen=input ("Enter a sentence: ")
index=0

for i in sen:
   if i<=len(sen):
       if sen[i]!=' ':
           print(sen[i])
exit()

You can just iterate trought the string, check for Spaces and then take the Charakter after the space:

def main(string):
    count = 0
    output = []
    for _ in string:
        if string[count] == ' ':
            output.append(string[count + 1])
        count += 1
    return output
        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM