Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ThinkPython Exercise 9.3
#11
Edited

After you were provided with a wealth of solutions, here's a my favorite - use the fact that the boolean equivalent of an empty set is False
def avoids(word, forbidden):
    return not set(forbidden).intersection(word.lower())
PS The name of function does not match the result - it returns True when a word is allowed and False when a word should be avoided, that has confused me. allowed_word would have been better name
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#12
Thank you all for your help.

@ThiefOfTime - I needed to add a float() before your "complete_count" and it works perfectly. Yes that's what I meant by running on its own. In my original code, I needed to type in cal_perc after the user prompt to calculate%.

@braun - I was using Python 3 originally but had trouble installing the Turtleworld module. I saw on some online forum saying that Turtle was incompatible with Python 3 so I switched to Python 2 but am still having issues. Do you have any tip or can point me to any useful troubleshooting sites? Thank you very much.
Reply
#13
(May-28-2018, 04:57 AM)sangurocactus Wrote: @braun - I was using Python 3 originally but had trouble installing the Turtleworld module. I saw on some online forum saying that Turtle was incompatible with Python 3 so I switched to Python 2 but am still having issues.
IMHO using packages/frameworks like Turtle in education is non-sense.
Given that because of this you had to switch python2 only proves me right. Just find another tutoring material and work on python3 (my understanding is Turtle is not requirement imposed on you by teacher/school)
Based on this:
https://greenteapress.com/wp/think-python-2e/
Second edition is targeted at python3

This does not change my principle opinion on swampy/Turtle... i.e. packages written by the author for the single purpose to teach using them... It only confuses...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#14
@braun - thanks for the advice. I will skip the chapter on using Turtle. It seems nonsensical that I am spending more time installing a module than learning the language.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ThinkPython Exercise 9.2 sangurocactus 6 4,759 May-23-2018, 04:17 PM
Last Post: sangurocactus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020