H
H
Hikikomori912015-09-24 03:42:25
Python
Hikikomori91, 2015-09-24 03:42:25

Why is the element not being replaced?

Another cancer question from the ten-day helloworld

def capitalise():
    global words
    i=0
    for elem in words:
        if i == 0:
            elem = ord(elem) - 32
            elem = chr(elem)
            words.replace(words[i], elem)
        if elem == " ":
            i = -1
        i+=1
    return words
        
words = input()
capitalise()

So, the input is given a string, in each word of which you need to capitalize the first letter. It turns out that the function returns a virgin string, untouched by my manipulations with replays. Tell me what I did wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-09-24
@Hikikomori91

in the described task, everything is wrong, because here and here,
well, at the same time, familiarize yourself with what and how replace
does and you can code it , but it’s better without it: in addition to the very delusional
nature of such an activity, words are not necessarily separated by spaces.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question