Python

# In this example we see how to set variables in python as well as use an if statement, use index and slice, and an and comparison statement

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
print ('Welcome to the Pig Latin Translator!')


pyg = 'ay'

original = input('Enter a word:')

if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  new_word = word + first + pyg
  new_word = new_word[1:len(new_word)]
  print (new_word)
else:
  print ('Invalid. Please type a word, characters only')

"""
print welcome
set pyg variable to "ay"
set original variable to collect input
if statement asks if the length of the original varaible      entered is greater than 0 AND is just characters then      then we proceed if not it fails and we go to else.
if statement is true we set the original variable to all lowercase and give it the new variable of word
we set a new variable called first to