Pyg latin exercise


#1

I am going through the pyg latin exercise.Facing a bit of problem.This is the code i ma using.

pyg='ay'
#Enter a word
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:]
 print ("new_word)
else:
 print ("empty")

After this, when i enter a word,it shows invalid syntax.Please enlighten.


#2

actually there's a " missing in print.But i have included it in the coding.Still it throws an error.


#3

here:

print ("new_word)

like you said there is a quotation mark missing, but i would actually remove the quotation mark rather then adding one, this way you print new_word variable which contains the pyglatin translation of the user input

also, you should use raw_input(), using input() means the input is evaluated as code


#4

Thank you!Actually i tried using raw_input()But it throws an error.


#5

whenever i try using raw_input,it shoes as raw_input is not defined.


#6

that is weird, sometimes it goes wrong. Try refreshing the page/different browser

if you need more help, post an updated version of your code


#7

I am using python 3.4.3. the latest version is not compatible with my system.


#8

including that you use python3 is quit important, then you need to use input()

So, all good now?


#9

Yes,its fine.Thank you again!!


#10

This script works fine in the shell.But when i try running in the compiler,its shows the message "please enter a word".But when i enter a word and press enter the compiler closes.

pyg='ay'

Enter a word

original=input("please 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:]
print(new_word)
else:
print(empty)


#11

python is an interperted language, not a compiled one. And compilers most certainly don't close, the window you run the program in closes, you mean?

Well, what reason would there be for the window to stay open after the program finishes running?


#12

I understand that.What i mean to say is that it does not show the output,it closes before that.


#13

you didn't answer my question

there is no reason for CMD to stay open, you could simply prompt the user:

input("press enter to exit")

at the end


#14

I have added that to the script.Still facing the issue.


#15

That can't be, but for me to troubleshoot such an issue on the forum is pretty tricky (Besides you providing very little information, no code, are you running in CMD? i assume at this point, but you are not telling me)

press start + r or search for run in the start menu and run cmd, navigate to the directory where you stored the python script and run: python scriptname.py (or python3 scriptname.py, depends on your installation)


#16

I am not running in CMD.I have given the code in my previous post.

pyg='ay'

Enter a word
original=input("please 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:]
print(new_word)
else:
print(empty)


#17

And i have added this too input("please press return to exit")


#18

okay, I will do it.Thank you


#19

the input() keeps the window open because it needs input. I have done it dozen times. I don't know what you did that doesn't work. Make sure the file is saved

I run out of ideas, did you run the script from the command line? That should work

its important to understand that any window you see on your computer (your browser, spotify, you name it) is basicly an infinity loop. That is what keep windows open, otherwise just close after opening.


#20

Okay.And i didnt run the script from command line.Anyway thank you very much.