1 Replies - 1072 Views - Last Post: 11 March 2013 - 05:51 PM Rate Topic: -----

#1 2574  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-March 13

Case Manipulation - strings and for loops

Posted 11 March 2013 - 01:55 PM

Hi, I'm new to Python and I'm working with strings and for loops.

Can someone tell me how I can alternate capital and lowercase letters in a sentence? I know how to convert an all-capital word into lowercase, and vice versa. But I can't seem to figure out how to alternate letters in a sentence.

For example, if I write: The dog is sitting.

I would like it to come out as: ThE DoG Is sItTiNg.

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Case Manipulation - strings and for loops

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5757
  • View blog
  • Posts: 12,571
  • Joined: 16-October 07

Re: Case Manipulation - strings and for loops

Posted 11 March 2013 - 05:51 PM

Think about it differently.

Can you make "The dog is sitting." come out as "T.h.e. .d.o.g. .i.s. .s.i.t.t.i.n.g...". You must break your sentence into letters. Once you can do that, then the solution is easy. Consider that a string can be treated as a list of characters.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1