thinkpython | think python : how to think like a computer scientist 中文翻译 | Learning library
kandi X-RAY | thinkpython Summary
kandi X-RAY | thinkpython Summary
think python:how to think like a computer scientist 中文翻译
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of thinkpython
thinkpython Key Features
thinkpython Examples and Code Snippets
Community Discussions
Trending Discussions on thinkpython
QUESTION
I'm learning Python (for fun) through the book ThinkPython. So far I'm really enjoying this new hobby. One of the recent exercise was crafting a Archimedes spiral.In order to test my skills I've been working on making a hyperbolic spiral but have been stumped!
according to the equation r=a+b*theta^(1/c)
- when c=1 we see a Archimedes spiral
- when c=-1 we should see a hyperbolic spiral
I'm using the following code and would appreciate any help towards the right direction.
- Extra points to whoever can help me in the right direction without directly giving away the answer. Unless it's simply a formatting issue.
- No points if the answer suggested involves using (x,y) coordinates to draw.
ANSWER
Answered 2020-May-01 at 05:51Simply adjusting the constants passed to draw_spiral()
as arguments:
QUESTION
Link to the Exercises can be accessed here - Case Study: Interface Design, Exercise Section 4.3
Quoting the question, it seems I have to implement an arc()
function:
Make a more general version of
circle
calledarc
that takes an additional parameterangle
, which determines what fraction of a circle to draw.angle
is in units of degrees, so when angle=360,arc
should draw a complete circle.
The code I've written so far:
...ANSWER
Answered 2018-Oct-11 at 18:23I'm trying to ... call the circle() function within arc() just as polygon() was called within circle()
You've got this backward. The problem states:
Make a more general version of circle called arc
Just as you could draw a circle with the more general function polygon()
, you should be able to draw a circle with the more general function arc()
. Here's a skeletal program for thinking about this:
QUESTION
Doing this exercise from ThinkPython and wanting to do a little extra, trying to modify the exercise function (avoid) to prompt the user repeatedly and perform the calculation to find how many words in a text file (fin) contain the user inputted letters (avoidprompt). It works the first time but after it prompts the user for input again it always returns an answer of 0 words.
Feel like the most likely issue is I'm misunderstanding how to use the while loop in this context since it works the first time but doesn't after that. Is there a better way?
...ANSWER
Answered 2019-Jun-17 at 00:21When you open a file and do for line in file
, you've consumed the entire file.
There are two easy solutions:
1) Go back to the start of the file in each iteration of your while(True)
loop, by doing fin.seek(0)
2) Just store the file contents in a list, by replacing the first line of your script with fin = open('file.txt').readlines()
QUESTION
(I muddled up the question in the beginning, sorry lol long day.)
I'm pretty much a beginner learning to code in python using the thinkpython pdf. One of the questions asked is to write a function to build a word list using append
and t = t+[x]
. According to my results, append is significantly faster, but I don't have a clue why.
ANSWER
Answered 2019-Feb-07 at 07:02The + operation adds another element to the original array. The append operation inserts the array or object into the end of the original array, which results the append uses less memory.
QUESTION
I am trying to add minutes to another timestamp. My code looks like below
...ANSWER
Answered 2018-Sep-27 at 11:24Change
QUESTION
It's the last piece of code I cannot grasp from the official solution for the PokerHand
exercise from ThinkPython book:
and
...ANSWER
Answered 2017-Oct-27 at 09:50dict.setdefault()
returns the value for the given key (having optionally set a default value first, if the key is missing).
The d.setdefault(c.suit, PokerHand()).add_card(c)
expression makes sure there is a value for the c.suit
key, and returns that. The default is PokerHand()
, an instance of a class that defines the add_card()
method.
Split it out into two statements, if that makes it easier to read:
QUESTION
I will try to be concise. The background for this issue is that I'm familiar with Python, however I am BRAND NEW to django. This book is my first exposure to it and I've come to find the more I work through the book that online Q/A's for django are not very general, thus making it harder to "just google it" and find an answer.
- MY ENVIRONMENT
Resource: Tango with Django (for version 1.9/1.10)
Distro: Elementary OS, Patched to the latest
Python Version: 3.5
Django Version: 1.11.x
- MY PROBLEM
What Is my Error: django.core.exceptions.FieldError
What are the Details: Invalid field name(s) for model Page: 'category'.
What does the Error mean?: Per The Docs, This error is raised when there is a problem with a field inside a model..Of the
reasons listed The following look relevant to my issue:
The Traceback
...ANSWER
Answered 2017-Sep-24 at 18:00class Page(models.Model):
Category = models.ForeignKey(Category)
QUESTION
These are the questions. I successfully completed Question 1 but I am just adding it for context. I am having trouble with Question 2.
...ANSWER
Answered 2017-Jul-13 at 17:55Because bob
is an instantiation of the Turtle
class and fd
is a class function, there is an implicit self
passed when the function is called. If you were to look at the definition for fd
in the Turtle
class, you would see something like def fd(self, distance)
. When calling the class function bob.fd(t, length)
, the self
argument is passed with the instantiation of the class implicitly, and then you are passing 2 additional arguments (t,length)
, for a total of 3 arguments.
QUESTION
From near the end of chapter 5 in the Tango With Django tutorial book, I have created a script used to populate a SQLite database with test data which is called:
~/Workspace/wad2/tango_with_django_project/populate_rango.py
After receiving an error, I tried directly copy-pasting the script from the book and still received the following errors:
ANSWER
Answered 2017-Jan-27 at 15:05In order for your Django project to load the settings as tango_with_django_project.settings
, wad2
needs to be on the Python path.
The easiest fix is to move populate_rango.py
up a directory from wad2/tango_with_django_project/
to wad2
.
Alternatively, you can add the parent directory to the python path in populate_rango.py
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install thinkpython
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page