PygLatin, how can I make this run with python 3.6.4


#1

I tried to run:

pyg = ‘ay’

original = raw_input(‘Enter a word:’)
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
if first == (‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’):
new_word = word + pyg
print (new_word)
else:
new_word = word[1:] + first + pyg
print (new_word)
else:
print ‘empty’

in command prompt with python 3.6.4, I changed some of the syntax to this in attempt to make it run:

pyg = ‘ay’

original = input(‘Enter a word:’)
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
if first == (‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’):
new_word = word + pyg
print (new_word)
else:
new_word = word[1:] + first + pyg
print (new_word)
else:
print (‘empty’)

but all I keep getting is:

IndentationError: unexpected indent

first = word[0]

File “”, line 1
first = word[0]
^
IndentationError: unexpected indent

if first == ('a' or 'e' or 'i' or 'o' or 'u'):

File “”, line 1
if first == (‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’):
^
IndentationError: unexpected indent

    new_word = word + pyg

File “”, line 1
new_word = word + pyg
^
IndentationError: unexpected indent

    print (new_word)

File “”, line 1
print (new_word)
^
IndentationError: unexpected indent

else:

File “”, line 1
else:
^

how do I fix this so I can run it with 3.6.4 on command prompt?


#2

Indentation has meaning, it’s not something you just shuffle around to make it “work”, and it’s not treated differently in python2 and python3 so long as you don’t mix tabs and spaces which you shouldn’t do anyway


#3

I edited it to
pyg = 'ay’
original = input(‘Enter a word:’)
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
if first == (‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’):
new_word = word + pyg
print (new_word)
else:
new_word = word[1:] + first + pyg
print (new_word)
else:
print (“empty”)

now what I got was

File “”, line 7
else:
^
SyntaxError: invalid syntax

print ("empty")

File “”, line 1
print (“empty”)
^
IndentationError: unexpected indent


#4

You should do what @ionatan said about indentation, because you code is fine with the correct indentation.


Solution code:

pyg = "ay"
original = input("Enter a word: ")
if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  if first == ("a" or "e" or "i" or "o" or "u"):
    new_word = word + pyg
    print (new_word)
  else:
    new_word = word[1:] + first + pyg
    print (new_word)
else:
  print ("empty")

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.