If you’re learning anything at all, it is that there are workarounds. Put that learning to use.
Trying to add into the translator. I have done the below so far to allow the ability to escape if someone types in wrong input. What I would like to happen is if the input is wrong to be prompted again for a word and if wrong 3 times then ask if they want to quit. I was thinking a loop but I started with the below and it feels clunky and I want to implement this correctly. I know that a function could do this but memory limits etc… Thanks in advance for the help.
pyg = 'ay' original = raw_input('Enter a word: ') if len(original) > 0 and original.isalpha(): word = original.lower() first = word new_word = word + first + pyg new_word = new_word[1:len(new_word)] print new_word else: print 'No Numbers or Spaces.. only letters' while True: cmd = raw_input('Do you want to quit? Enter \'q\'!') if cmd == 'q': break
I keep getting: Traceback (most recent call last):
File “python”, line 3, in
ExecTimeoutException: Program took too long to terminate.
After you click Run, be sure to click the prompt in the console. Then type a word and Enter. If that doesn’t work, then comment out the input statement and assign a literal value so you can run the program to a final result. That will get you through the exercise.
This is my code:
pyg = ‘ay’
original = raw_input(‘Enter a word:’)
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
When I type anything, why does it return ‘empty’?
Comment out that line and just hard code a word.
original = "surprise"
Then you can see the code run and pass the lesson.
I had to put show solution to every exercise because it wouldn’t let me move forward. Where do I type the word to enter into the translator?
worked very well for me!!! THANKS!! do you know why theres a difference between the space between : and 'tho?
It’s simply for visual effect. Without it, there wouldn’t be a space between the colon and the user’s input in the console.
Enter a word:hello
Enter a word: hello
Thanks for the reply. However, I think there’s more than that as there’s a difference in the output.
When I type
original = raw_input (‘Enter a word:’)
original = raw_input ('Enter a word : ')
the first one prints empty no matter what’s my input.
What do you mean by “prints empty”?
according to the instructions, as I recall.
my bad, I tried to say it prints nothing at all for the first input. my code now, but my question was similar to sliosi, and was solved by the space issue suggested by design7184503999 - wanted to know why did the space change the output… it somehow works now; sorry if i caused any confusion
raw_input seems not working for this lesson.
I am using the solution or replacing raw_input with string to proceed.
I need help, my code is the same as the solution, but it keeps saying that there is an error on line three?
Suggest read through this topic and note some of the suggestions and workarounds.
Hello my code isn’t working it isn’t even repeating the word
Hey! I hope you all are doing allright!
I’ll start by saying that I started this course few months ago, but I didn’t complete it, so I’m doing all the exercises again. I felt this exercise had many redundancies, but I get it, since the point of it is to let people use everything they’ve learned up to this point. Anyways, at the very last exercise I changed some things just to make the code a bit more straightforward and a bit less boring. In this process, I used a few bits of code that have not been studied up to this point in the course, and even though it is good (I think), I still think it could be better.
I want to share my code with the community, with it’s improvements and it’s flaws. If you are more experienced, I hope you can give me some feedback on how to make better code, and if you are a begginer, please learn from what I did right or wrong, according to what the more experienced people say.
I’m having trouble understanding why len is used here:
new_word = new_word[1:len(new_word)]
If you just wanted 1: of new_word, what is the purpose of len here? Thanks!
It’s just there to show explicitly what the value will be if that parameter is left off.