Jump to content

billy91

Members
  • Posts

    1
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

billy91's Achievements

  1. I'm now working on the strange case problem. Write a function toWeirdCase (weirdcase in Ruby) that receives a string and returns it with all even indexed letters in each word upper cased and all odd indexed characters in each word lower cased. Because the indexing described above is zero-based, the zero-ith index is even, hence that letter should be capitalised. The function was written by myself. def to_weird_case(string): tot="" for i in range(len(string)): if i%2==0: tot+=string[i].upper() if i%2==1: tot+=string[i].lower() if string[i]==" " or i%2==1: to_weird_case(string[i:]) return tot It correctly swaps the case of a single word, but it does not work for several words or a phrase. I considered using swapcase, but it swapped all the words in the sentences, which is undesirable. So, by chance, I received this type: toWeirdCase should return the correct value for a single word (8 of 8 Assertions) should return the correct value for multiple words 'ThIs iS A TeSt' should equal 'ThIs Is A TeSt' 'LoOkS LiKe yOu pAsSeD' should equal 'LoOkS LiKe YoU PaSsEd' 'ThIs iS ThE FiNaL TeSt cAsE' should equal 'ThIs Is ThE FiNaL TeSt CaSe' 'JuSt kIdDiNg' should equal 'JuSt KiDdInG' 'Ok fInE YoU ArE DoNe nOw' should equal 'Ok FiNe YoU ArE DoNe NoW'\ I saw an article that suggests dividing the sentence and applying the function to each word, but making all words uppercase. So, can somebody assist me?
×
×
  • Create New...