r/inventwithpython • u/redzeusky • Jul 29 '14
Sharing your python creations online
Is there a site where I could post my pygame creation so that a group of friends could play it?
r/inventwithpython • u/redzeusky • Jul 29 '14
Is there a site where I could post my pygame creation so that a group of friends could play it?
r/inventwithpython • u/FractiousBetaMale • May 21 '15
Hi. I love the book. I am finding it incredibly useful. I have a hard time knowing exactly when to call myself "Done" with a chapter, but I just try to study it and absorb the knowledge as best I can. Then I get frustrated. Then I leave for a few days and come back and tackle it with a clearer head.
I'm getting to the point where the code for Tic-Tac-Toe is starting to make sense to me, but there's one bit that really goes over my head and I think it might be crucial to my overall understanding of programming concepts.
Starting at line 53 in the book's source code, it has a block that looks like this:
return ((bo[7] == le and bo[8] == le and bo[9] == le) or
(bo[4] == le and bo[5] == le and bo[6] == le) or and so on, to check if the player has won.
The book says that we use "bo" and "le" as shorthand for the variables, so that we don't have to do as much typing. Because (bo, le) is in the parameters of the function, I believe the function will return the value of that big honking code block to the parameters bo and le. PLEASE jump in and correct me if I'm misunderstanding the way parameters work, or clarify further if that is correct, because I feel like functions and parameters are still going a little bit over my head and it's keeping me from comfortably going any further.
The question, in short, is once that value goes into the (bo, le) variables, how does that...affect the rest of the board? Or how is it affected by the rest of the board? I feel like every other function that changes the board or affects the flow of the game at all uses the variable "board." It's just this one function that uses "bo." So how does this function know whether the board is filled in, and how does the rest of the program know when this function returns true, if they're using different variable names?
Sorry if that got a little muddled. I'm relatively new and these concepts are still pretty slippery for me, so my post reflects my current sort of frazzled stream of consciousness.
Thanks in advance.
r/inventwithpython • u/JackSimite • Jan 09 '16
Hi guys, I've got to chapter 6 in this book and the practice project says ' The printTable() function can begin with colWidths = [0] * len(tableData), which will create a list containing the same number of 0 values as the number of inner lists in tableData'
however after the following:
tableData [['apples','oranges','cherries','bananas'], ['Alice', 'Bob', 'Carol', 'David',], ['dogs', 'cats', 'moose', 'goose']]
colWidths = [0] * len(tableData)
print(colWidths)
I get the following list:
[0, 0, 0]
I was expecting:
[8,5,5]
Can anyone help where I am going wrong?
Thanks
r/inventwithpython • u/w00tasaurus • Jan 12 '16
Hey guys!
I'm having a slight issue with Chapter 6: Dragon Realm. I've made a slightly different version of the game using the provided source code. I had no issues and tested every aspect of it to find that it was working perfectly. After that, however, I went back and edited the portion where we define:
friendlyCave = random.randint(1, 2)
In my version, I am not using the random module and instead have separate outcomes depending on if you select cave 1 or 2, with 2 always being the friendly cave. However, I wanted different versions of these inputs to work for the user -- whether uppercase, numerical, alphabetical, etc. So my line of code looks like this:
friendlyCave = 2 or second or Second or 2nd
The issue I am having is that 2, second, and Second all work as intended, but for some reason typing in 2nd while playing the game prints my else outcome, rather than the if/friendlyCave outcome. I would have expected it to at least initiate the loop and ask the question again of which cave they choose if there was some problem. Why is it bringing the user to cave 1 rather than friendlyCave 2?
r/inventwithpython • u/AlSweigart • Aug 12 '13
Just a question for people learning from the "Invent with Python" books. What are some programming problems that you face, or other difficulties that you've had, when trying to learn from a book?
r/inventwithpython • u/wasansn • Jul 18 '16
I'm going through automate the boring stuff learning Python and I'm having a lot of fun.
I'm an overthinker and I'm taking my time to understand all of the elements before I move forward. I just did the collatz sequence. After looking at the answer, cross referencing going back and forth a few times I got it working.
But, this is bothering me. Here is the stack overflow answer. http://m.imgur.com/kW4jP1V
It is correct and works for me.
But what is going on here.
n = input("Give me a number: ") while n != 1: n = collatz(int(n))
How is n = collatz(int(n)) valid?
n is a variable but then it calls a function and passes the argument of n, this is referencing itself right?
Does this mean that n exists in multiple places and that it is handled by Python and we never see it?
I assume that n1 = (collatz(n2)) where n2 is passed to the function and passed back to n1 when the function is complete.
r/inventwithpython • u/[deleted] • Mar 30 '18
I just finished inputting the code for Dragon Realm and have gone through the following paragraphs (in the book) that explain the code. I can follow the execution order more or less fine but I'm still a bit confused about how one part of the code works.
Specifically I'm confused about "return cave"
I get that it breaks the function defined by def chooseCave - and I get that it is returning the value inputted by the user; and I also get that "return cave" only does its thing once the user has provided a 1 or 2 and no other value.
What I don't understand is where the "return cave" statement is sending the value of "cave" to. Is it sending it to the "chosenCave" part of this line: "def checkCave(chosenCave):" ?
if so, how does Python know to send it there? and can the parenthesis of said defined function really contain a variable? I feel like I was following everything just fine until this came along.
#Dragon Realm
import random
import time
def displayIntro():
print('''You are in a land full of dragons. In front of you,
you see two caves. In one cave, the dragon is friendly
and will share his treasure with you. The other dragon
is greeedy and hungry, and will eat you on sight.''')
print()
def chooseCave():
cave = ''
while cave != '1' and cave != '2':
print('which cave wwill you go into? (choose 1 or 2)')
cave = input()
return cave
def checkCave(chosenCave):
print('you approach the cave...')
time.sleep(2)
print('It is dark and spooky...')
time.sleep(2)
print('''A large dragon jumps out in front of you!
He opens his jaws and...''')
print()
time.sleep(2)
friendlyCave = random.randint(1, 2)
if chosenCave == str(friendlyCave):
print('... Gives you his treasure!')
else:
print('...Gobbles you dowwn in one bite!')
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y':
displayIntro()
caveNumber = chooseCave()
checkCave(caveNumber)
print('Do you wish to play again? (yes or no)')
playAgain = input()r/inventwithpython • u/memphho • Apr 07 '14
I can't seem to find http://invpy.com/hackingtraces
anyone any help?
r/inventwithpython • u/stever777 • Feb 12 '18
Hope I didn't inadvertently mis-title the orginal post as 'Hacking Secret Ciphers with Python'....I didn't have the book in front of me while posting.
Repeating original question here Hello Mr. Sweigart,
Just finished the book - I've never seen the math behind public key encryption, so really appreciated the clear and detailed walkthrough
Had a question regarding the 'Converting a block to a String' section. In this section, you state that in order to retrieve the original message text, the length of the original message must be known.
Is there another way to recover the original message text ? It seemed a odd that the length of the original text must be exposed to the person decrypting the message. Granted, you stated in the beginning of the chapter that this approach was only based on the RSA cipher, and there may be a part of the process you didn't talk about in your book - but if the original message length is something that has to be communicated to the person decrypting the message, how is this usually accomplished ? is it sent along with the encrypted message ?
Appreciate any additional insight you can provide on this part of the process.
r/inventwithpython • u/HussamNEO • Feb 17 '18
r/inventwithpython • u/rkj2175 • Sep 23 '17
I'm constantly having problems running even the most simple modules. When I can get one to work, it won't work all the time. I've done the first 4-5 lessons and I've only got two to work.
For example; the most basic, the variable; I type Rec = 3, but when I type this or other variables, I get "Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> Rec NameError: name 'Rec' is not defined"
Sometimes it works, but most of the time it doesn't.
When I run import random
random.randint(1, 20) all I get is this error message. RESTART: C:\Users\user\AppData\Local\Programs\Python\Python36-32\Random Number.py
r/inventwithpython • u/MasterOfProgramming • Feb 24 '15
This isn't really a question, but in Ch. 18 Collision Detection, I noticed something that would be really slow with the collision detection. The worst case scenario would be that it searches through every single pixel in one rectangle before it detects overlapping between them.
The much better way to do collision would be something like Separating Axis Theorem. Which ever rectangles' right X is furthest to the right, take it and average it with the left X of the other point, and the same for top and bottom Y. Check only the point of the coordinated found. If that point is inside either rectangle, they overlap.
r/inventwithpython • u/DrDeleto • Oct 24 '15
In Chapter 12 from Automate the Boring Stuff, in excersise 'Getting sheets from the workbook', when I call wb.get_active_sheet() I get the following error:
/usr/lib/python3.5/site-packages/openpyxl/workbook/workbook.py:102: UserWarning: Call to deprecated function or class get_active_sheet (Use the .active property). def get_active_sheet(self):
I understand that I have to write a function calling the .active property. But I don't know how to do that. I tried looking in the openpyxl documentation, but there is no information on the new method. Can anyone tell me how to get the active sheet in an Excel file? Thank you in advance.
r/inventwithpython • u/[deleted] • Apr 22 '17
I am having issues understanding how to run the script from Windows 10. I believe I correctly added the path to the environment variables. I created a batch file for this program. When I go to type pw email into the WIN-R window, it just comes back saying that Windows cannot find pw.
At this point I just am lost in this whole process. Can someone give me a step-by-step instruction on how to run a python script from Windows 10?
r/inventwithpython • u/Affectionate-Bad9435 • Jan 16 '26
In the book "Automate the Boring Stuff with Python, 3rd Ed" there is an instruction to install pytesseract On Linux: pip3 install pytesseract==0.3.10
This does not work in latest release of Linux Mint, or may be obsolete. What is the correct one?
r/inventwithpython • u/AlSweigart • May 24 '26
r/inventwithpython • u/AlSweigart • May 07 '26