Python Forum

Full Version: Ignoring non characters in a string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm quite new to python .
I have written a pigLatin code and I need the code to ignore non characters i.e. I want them to stay where they are in a string. So for instance take '1myth' when this is converted to piglatin I want it to be for example 1ythmway where the number is not affected
Here is my code below :

Vowels =("aeiouAEIOU")
y = input("\n Enter sentence ")
x = y.split()
for word in x:
if word[0] in Vowels:
      word +='hay'
              
elif all(char not in Vowels for char in word):
          word = word[1:] + word[0]                                                                                                                          
          word += 'way' 
            
elif a[0] not in Vowels:
          for i, j in enumerate(a):
              if j in Vowels:break
          word = a[i:] + a[:i]
          word += 'ay'
             
        print(word, end = ' ')

I realised my code had an error so i have updated it below:
Vowels =("aeiouAEIOU")
y = input("\n Enter sentence ")
x = y.split()
for word in x:
 if word[0] in Vowels:
      word +='hay'
               
 elif all(char not in Vowels for char in word):
          word = word[1:] + word[0]                                                                                                                          
          word += 'way' 
             
 elif word[0] not in Vowels:
          for i, j in enumerate(word):
              if j in Vowels:break
          word = word[i:] + word[:i]
          word += 'ay'
              
          print(word, end = ' ')
Create the following function near top of program:
def has_digits(word):
    return any(character.isdigit() for character in word)
test:
Output:
>>> has_digits('blinky') False >>> has_digits('bli2nky') True >>> has_digits('123') True >>>