Python Forum
"If Len(Word) == 0" Code Block in Pig Latin Program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"If Len(Word) == 0" Code Block in Pig Latin Program
#4
It could be that or it could be to just skip any non-alphabetic "words" such as numbers. In "Welcome 2022!" you don't want 2022! to be altered. When this code processes "2022!":
     while len(word) > 0 and not word[0].isalpha():
          prefixNonLetters += word[0]
          word = word[1:]
It will move all the characters from word to prefixNonLetters and you'll end up with prefixNonLetters == "2022!" and word == "". len(word) == 0, so append "2022!" to pigLatin and move on to the next word.
Reply


Messages In This Thread
RE: "If Len(Word) == 0" Code Block in Pig Latin Program - by deanhystad - Jan-02-2022, 06:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  non-latin characters in console from clipboard Johanson 3 739 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  python multiple try except block in my code -- can we shorten code mg24 10 6,325 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,556 Aug-12-2021, 04:25 PM
Last Post: palladium
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 2,362 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Some Code For a program PythonCodeMaker_119 2 2,360 Apr-14-2021, 08:47 PM
Last Post: BashBedlam
  Pressing non-latin characters? Murlog 0 1,545 Jul-25-2020, 03:10 PM
Last Post: Murlog
  Modify code from running program ? samuelbachorik 2 2,471 Jun-26-2020, 08:17 PM
Last Post: samuelbachorik
  Python Speech recognition, word by word AceScottie 6 16,089 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  Block of code, scope of variables and surprising exception arbiel 8 3,472 Apr-06-2020, 07:57 PM
Last Post: arbiel
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,926 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020