def to_weird_case(string): num = 0 new_word = [] for i in string: if num % 2 == 0: num += 1 i.upper() new_word.append(i) else: num += 1 i.lower() new_word.append(i) print(new_word) to_weird_case('Test for test') Greetings to all, I ran into the task of changing the case of characters so that from this line: Test for test turned out: TeSt FoR tEsT . The functions upper () and lower () do not change case. What's the catch? Changed the result that should get, litter did not see, you need to make the first character uppercase, second lowcase, etc. in turn!
def to_weird_case(string): num = 0 new_word = [] for i in string: if num % 2 == 0: num += 1 new_word.append(i.upper()) else: num += 1 new_word.append(i.lower()) print(''.join(new_word)) With your help, the code works, thanks! There is a task to implement words with spaces.
to_weird_case('Weird string case') # => returns 'WeIrD StRiNg CaSe' I can break a line like this:
s = 'Weird string case' l = s.split() s1 = '' for i in l: s1 += i + ' ' print(s1) And then for each word to apply the previous code, but it is clear that this is not the right decision, tell me how to implement?
i.lower()andi.upper()do not change the original string, but return the modified string. In your code, you just need to donew_word.append(i.lower())andnew_word.append(i.upper()). Well, then when turningnew_wordturn it from list to line:''.join(new_word). - insolor 2:51 pm