Re: [Tutor] Need help with code
You most likely have no file named words.txt in the directory from which you are running your code. On Mon, Apr 17, 2017 at 10:12 PM, Tyler Seacristwrote: > Hello, > > > How do I avoid this error message everytime I utilize wordlist = > open("words.text") ? > wordlist = open("words.txt") > Traceback (most recent call last): > File " ", line 1, in > wordlist = open("words.txt") > FileNotFoundError: [Errno 2] No such file or directory: 'words.txt' def calculate_abecedarian(): > total_count = 0 > for word in wordlist: > if is_abecedarian(word): > print (word) > total_count += 1 > return total_count > > or > if __name__ == '__main__': > fin = open('words.txt', 'r') > print (no_contain(fin)) > > > Traceback (most recent call last): > File " ", line 2, in > fin = open('words.txt', 'r') > FileNotFoundError: [Errno 2] No such file or directory: 'words.txt' > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with code
On 18/04/17 03:12, Tyler Seacrist wrote: > How do I avoid this error message everytime I utilize wordlist = > open("words.text") ? > wordlist = open("words.txt") > Traceback (most recent call last): > File "", line 1, in > wordlist = open("words.txt") > FileNotFoundError: [Errno 2] No such file or directory: 'words.txt' You need to tell Python where the file lives. It is evidently not in the same folder where you run the program(*) so you need to provide the path. (*)You can determine which folder python considers its home folder by including this code in your program; import os print( os.getcwd() ) # get Current Working Directory and you can see its contents with print( os.listdir() ) So you need to provide the path. If you are using Windows you should put an 'r' in front of the path, like so: fin = open( r"C:\Path\to\words.txt" ) or use forward slashes: fin = open( "C:/Path/to/words.txt" ) Either technique will avoid python interpreting the '\' as an escape character. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Need help with code
Hello, How do I avoid this error message everytime I utilize wordlist = open("words.text") ? >>> wordlist = open("words.txt") Traceback (most recent call last): File "", line 1, in wordlist = open("words.txt") FileNotFoundError: [Errno 2] No such file or directory: 'words.txt' >>> def calculate_abecedarian(): total_count = 0 for word in wordlist: if is_abecedarian(word): print (word) total_count += 1 return total_count or >>> if __name__ == '__main__': fin = open('words.txt', 'r') print (no_contain(fin)) Traceback (most recent call last): File " ", line 2, in fin = open('words.txt', 'r') FileNotFoundError: [Errno 2] No such file or directory: 'words.txt' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with code
On Mon, Apr 17, 2017 at 12:00 AM, Alan Gauld via Tutorwrote: > On 16/04/17 18:26, Tyler Seacrist wrote: > >> I need to draw a stack diagram for print_n >> called with s = 'Hello' and n=2 and am unsure of how to do so. Are you referring to this? http://www.greenteapress.com/thinkpython/html/thinkpython004.html#toc33 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with code
On 16/04/17 18:26, Tyler Seacrist wrote: > I need to draw a stack diagram for print_n > called with s = 'Hello' and n=2 and am unsure of how to do so. Me too. What is print_n? Which stack? One in your program or the interpreters internal stack? We need a lot more detail. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Need help with code
Hello, I need to draw a stack diagram for print_n called with s = 'Hello' and n=2 and am unsure of how to do so. Thanks, Tyler ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help writing code with python
On 02/07/2015 05:36 PM, Conner Wood wrote: I fell behind 2 weeks in my class due to surgery and have a coding project due tonight (Saturday, Feb. 7). I've attached my project to this email. Please help! Also, I'm using a Mac laptop if that helps in anyway. Please get back to me as soon as you can. Welcome to Python-tutor. This seems to be your first post. Thanks for making it a text email. And for mentioning your OS. But you also should be specifying the Python version. There's no attachment to your message in the mailing list. And many people here can't see attachments anyway. If your project is too big to include directly in your email message, you may be out of luck. How big a project is it, and how much of it have you been able to do so far? Is there some particular problem that has you stumped? We're here to help you get past some sticking point, not to do your assignment for you. I'd expect your prof would give you an extension if you can't get it in because of unexpected surgery. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help writing code with python
On 07/02/15 22:36, Conner Wood wrote: I fell behind 2 weeks in my class due to surgery and have a coding project due tonight (Saturday, Feb. 7). I've attached my project to this email. Please help! Also, I'm using a Mac laptop if that helps in anyway. Please get back to me as soon as you can. First. We won't do homework for you so we need to see what you have done. You need to have made some kind of attempt. Or at least have some specific questions. Second Asking for a response on the day that the assignment is due on a mailing list isn't going to work, it didn't get here until Sunday. I hope you got something done on Saturday but you need to give a mailing list a bit more notice. Email can take up to 24 hours to reach its destination, never assume it will be quicker than that (even if 99% of the time it is). Third, The attachment didn't get here. So I've no idea what your assignment was. Its usually better to copy the text into the mail body. Fourth. Please give more than the fact you've got a Mac. So have I; its an old iBook that runs MacOS 10.4 on a 600MHz PowerPC chip. I suspect that's quite different to yours. Tell us the OS version and the Python version you are using. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help writing code with python
Alan Gauld alan.ga...@btinternet.com writes: Third, The attachment didn't get here. So I've no idea what your assignment was. Its usually better to copy the text into the mail body. Given that the attachment was described as “my project”, I would advise not sending it here in any form. Copy text here if it's *small*, and *focussed*, and relevant to some part of the discussion. If the text is “my project”, it's better not put here at all. I am glad the attachment was discarded, it sounds like sending it to all recipients of this forum would have been only an annoyance. Conner, please obtain the time to do the project unhurried; then, feel free to come to this forum with *focussed* questions on aspects of the Python code you are writing. We don't need to see the project. -- \ “I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__)it seriously.” —Douglas Adams | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Need help writing code with python
I fell behind 2 weeks in my class due to surgery and have a coding project due tonight (Saturday, Feb. 7). I've attached my project to this email. Please help! Also, I'm using a Mac laptop if that helps in anyway. Please get back to me as soon as you can. Thanks, Conner Wood ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help writing code with python
Conner Wood cwood1...@gmail.com writes: I fell behind 2 weeks in my class due to surgery and have a coding project due tonight (Saturday, Feb. 7). I've attached my project to this email. My sympathies with your situation, I hope your surgery was successful and you are in good health. This is not a forum for doing your project; you will need to do your own project. Rather, this is a forum for publicly discussing much more focussed topics. We tutor each other in learning Python and its idioms and ecosystem. We don't do one-on-one tutoring, and we don't do coding for you. If you have a *small* portion of code that demonstrates some behaviour that confuses you, we can talk you through the confusion (provided the code can also behave the same for us, and provided we know what you expected from that code). If you have a large project, you'll need to do the work, or get some largesse from the people expecting that work. It seems you have an entirely valid reason to ask for a time extension. Good hunting! -- \ “I knew things were changing when my Fraternity Brothers threw | `\ a guy out of the house for mocking me because I'm gay.” | _o__) —postsecret.com, 2010-01-19 | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with code.
Raj Medhekar wrote: Hi, I need help with the code below. I am trying to pair the list in the hint with the list of words. However, the list is not matching up correctly. Also when the correct guess is entered the program just continues without acknowledging the right answer. Please could y'all test this out and let me know where I am going wrong. I also want to add a scoring system where the computer rewards the person that guesses without getting a hint. Any suggestions as to how I might go about incorporating that into my code. Thanks for the help! Peace, Raj I will throw out a few hints below. I suggest you familiarize yourself with desk checking - walking through the program by hand , writing down the values of variables at each step, and tracking the loops and conditions carefully. # Word Jumble V2 # Computer jumbles a randomly selected word then asks the player to guess it # If player cant guess the word he can ask for a hint Note you don't offer a way to ask for a hint, you just give it. # Scoring system that rewards players for solving jumble without a hint (not included in this code) Get the rest working first. import random WORDS = (sweep,difficult, python, america) HINTS = (remove dirt,not easy,computer language and a snake, land of the free) word = random.choice(WORDS) correct = word jumble = while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position+1):] OK so far. The next loop does not make sense - it uses word to iterate thru WORDS but does nothing with word! Position is a constant (0) so all it does is compare remove dirt with sweeps 4 times. for word in WORDS: HINTS[position] == WORDS[position] print\ Welcome to Word Jumble Unscramble the letters to make a word Remember Hints lower your score (Press the enter key at the prompt to exit) print The jumble is: ,jumble guess = raw_input(Guess the word: ) guess = guess.lower() tries = 1 OK again. The while condition below does not make sense. word will always be america (can you see why?) while guess != word and word != and tries 5: print Sorry! That's not it! guess = raw_input(Guess the word: ) guess = guess.lower() tries +=1 if guess == correct: print You're right, the word is, word else: print Maybe you need a hint: print HINTS[position] guess = raw_input(Guess the word: ) guess = guess.lower() The program at this point is not in any loop so it terminates. raw_input(\n\nPress the enter key to exit:) -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with code.
Raj Medhekar wrote: Hi, I need help with the code below. I am trying to pair the list in the hint with the list of words. However, the list is not matching up correctly. Also when the correct guess is entered the program just continues without acknowledging the right answer. Please could y'all test this out and let me know where I am going wrong. I also want to add a scoring system where the computer rewards the person that guesses without getting a hint. Any suggestions as to how I might go about incorporating that into my code. Thanks for the help! Peace, Raj # Word Jumble V2 # Computer jumbles a randomly selected word then asks the player to guess it # If player cant guess the word he can ask for a hint # Scoring system that rewards players for solving jumble without a hint (not included in this code) import random WORDS = (sweep,difficult, python, america) HINTS = (remove dirt,not easy,computer language and a snake, land of the free) word = random.choice(WORDS) correct = word jumble = while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position+1):] for word in WORDS: HINTS[position] == WORDS[position] print\ Welcome to Word Jumble Unscramble the letters to make a word Remember Hints lower your score (Press the enter key at the prompt to exit) print The jumble is: ,jumble guess = raw_input(Guess the word: ) guess = guess.lower() tries = 1 while guess != word and word != and tries 5: print Sorry! That's not it! guess = raw_input(Guess the word: ) guess = guess.lower() tries +=1 if guess == correct: print You're right, the word is, word else: print Maybe you need a hint: print HINTS[position] guess = raw_input(Guess the word: ) guess = guess.lower() raw_input(\n\nPress the enter key to exit:) To start with, what did you possibly hope to do with: for word in WORDS: HINTS[position] == WORDS[position] The body of that loop does nothing at all. What you really wanted was: position = WORDS.index(correct) Next, examine the phrase: while guess != word and word != and tries 5: print Sorry! That's not it! Why would you be comparing 'guess' against the highest word in the list? Shouldn't you be comparing it to 'correct' ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor