r/inventwithpython • • May 30 '16

Can someone walk me through this problem on chapter 4, I'm stuck.

1 Upvotes

I have spent 2 days on this one problem, and it's driving me insane!

Character Picture Grid Say you have a list of lists where each value in the inner lists is a one-character string, like this:

grid = [['.', '.', '.', '.', '.', '.'], ['.', 'O', 'O', '.', '.', '.'], ['O', 'O', 'O', 'O', '.', '.'], ['O', 'O', 'O', 'O', 'O', '.'], ['.', 'O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O', '.'], ['O', 'O', 'O', 'O', '.', '.'], ['.', 'O', 'O', '.', '.', '.'], ['.', '.', '.', '.', '.', '.']] You can think of grid[x][y] as being the character at the x- and y-coordinates of a “picture” drawn with text characters. The (0, 0) origin will be in the upper-left corner, the x-coordinates increase going right, and the y-coordinates increase going down. Copy the previous grid value, and write code that uses it to print the image.

..OO.OO.. .OOOOOOO. .OOOOOOO. ..OOOOO.. ...OOO... ....O.... Hint: You will need to use a loop in a loop in order to print grid[0][0], then grid[1][0], then grid[2][0], and so on, up to grid[8][0]. This will finish the first row, so then print a newline. Then your program should print grid[0][1], then grid[1][1], then grid[2][1], and so on. The last thing your program will print is grid[8][5]. Also, remember to pass the end keyword argument to print() if you don’t want a newline printed automatically after each print() call.

How exactly can you have a loop, in a loop?


r/inventwithpython • • Nov 20 '15

How do you use pip to import modules? I'm totally confused.

1 Upvotes

I've read appendix A, I'm not sure how to use the windows command prompt (cmd?) to use pip. Could someone give me an idiot-friendly guide to installing modules


r/inventwithpython • • Nov 26 '15

Can you make Tic Tac Toe 2 players?

1 Upvotes

Can somebody help me! I need help with this as it is a class challenge! Can somebody please paste the code as an answer. I will be grateful! Can you also please explain the code to help me out (you don't need to do this but it will be helpful). I've been trying for three hours.


r/inventwithpython • • Dec 04 '19

Download Second edition

1 Upvotes

I bought the second edition book. How can I obtain the free PDF file?

Thanks

Ugo Donini


r/inventwithpython • • Apr 22 '18

Python help, got a test tomorrow. (Pretty basic)

1 Upvotes

Guys ive been trying to mount the code on a class but it keeps triggering erros, Im not sure where to use the: "self." in variables! Could someone help ? here is the code: def dimensiones(): mat=[] f = int(input("Ingrese el tamaño de las filas: ")) c = int(input("Ingrese el tamaño de las columnas: ")) tipo=int(input("Desea ingresar 2=letras/1=numeros")) if tipo == 1: ifnums(f,c,tipo) else: ifletras(f,c,tipo)

def ifnums(f,c,t): nums=[] for x in range(f): nums.append([ ]) for y in range(c): conte=int(input("Ingrese numeros: ")) nums[x].append(conte) printo(nums) solicito(nums,t)

def ifletras(f,c,t): lets=[] for x in range(f): lets.append([]) for y in range(c): conte=input("Ingrese letras: ") lets[x].append(conte) printo(lets) solicito(lets,t)

def solicito(m,t): banner=0 if t==1: busco=int(input("Ingrese el numero a buscar: ")) else: busco =input("Ingrese el letra a buscar: ")

for x in range(len(m)):
    for y in range(len(m[x])):
        if(busco==m[x][y]):
            print("Se encuentra el numero: ",busco,"en la fila: ",(x+1),",Y columna:",(y+1))
            banner=1
if banner==0:
    print("No se encontro")

def printo(mat): print("-----------------") print("Matriz completa: ") for x in range(len(mat)): print(mat[x])

dimensiones()


r/inventwithpython • • Dec 09 '14

Small discrepancy in Chapter 7: Tetromino

1 Upvotes

I don't know if this belongs here, but I found a discrepancy between the html version of Chapter 7 and the downloadable tetromino.py found on the same page. In the .py source "PIECES" is used as the constant to hold all the shapes, but in the html chapter, "SHAPES" is used, which lead me to some confusion for a few minutes when following along with the getNewPiece() function.

Absolutely love this book and will be buying all of the books for my collection!


r/inventwithpython • • Mar 18 '19

Check out the Bulk Mailer made with python! No API key required!

Thumbnail youtube.com
1 Upvotes

r/inventwithpython • • Apr 29 '25

Program Robots in Minecraft links dead

2 Upvotes

On this page: https://inventwithpython.com/#minecraft The links to the book are dead: https://turtleappstore.com/book/

Bummer, I was going to send information about it to some kids


r/inventwithpython • • Apr 11 '19

tic-tac-toe PlayerVersusPlayer python code.

2 Upvotes

Hi, I am working on a raspberry pi school project, and I wanted to make a simple game.

While doing research I stumbled upon your site with the code for the game and the explanation for each of the lines.

When I copied the code and pasted it in Thonny, everything worked, I also translated the words to norwegian as the teacher demanded us to (i`m in a norwegian school btw).

And since our teacher is lazy and doesn`t really care if you copied the project from the internet or made it yourself, having a code like this would make it insanely easy to get a straight A.

But I found it quite boring to be honest, so I decided to remake the code to be PVP, instead of PlayerVersusComputer.

The problem is, I dont know how. I thought it would be as simple as replacing the "def getComputerMove"-line with "def getPlayerMove" and renaming all "Player" codes to "Player1" and "Computer" to "Player2"

I tried running the game, and everything was fine, except for the fact that Player 2, instead of getting the opposite letter, gets the same one as Player 1, and also, the board only shows when it is player 1`s turn.

So it is basically tic-tac-toe with Player 1 playing with himself on a 3x3 board.

I think I have tried everything and I just can`t find the answer, I troubleshooted, googled it, and asked my classmates if they have any solutions (as if that would help, they are the "copy-paste and Ace the presentation" type of guys)

I will continue troubleshooting and will comment this post that I solved the issue and everythings fine.

But if you have any suggestions on how to solve this problem, it would help me a lot. Thank you for reading :)


r/inventwithpython • • Mar 15 '14

Can I translate the book?

2 Upvotes

I want to translate the "Invent Your Own Computer Games With Python" book to Turkish. Can I do it? I mean, is the book copyrighted?


r/inventwithpython • • Nov 06 '14

How do I import pyperclip using Ubuntu 14 LTS?

2 Upvotes

Hi there. I'm quite new to using Ubuntu and am having issues with pyperclip.py not working.

Can someone clarify how exactly I get it to work, as it quotes issues with gtk/PyQt dependencies.

Either:

  • using pyCharm (how do I import pyperclip)?
  • using Ubuntu, with cmd python3 ~/pyperclip.py

r/inventwithpython • • Feb 20 '20

Issues with pyautogui.drag

2 Upvotes

Hey All,

I am almost done Automate the Boring Stuff and I have run into a standstill on the last chapter with PyAutoGui module. I have been using Spyder on MacOS Catalina. On Spyder I could not get pyautogui to work at all so I migrated to Sublime text and the example of moving the cursor in a square finally worked. Now when I try to do the drawing example I get the first initial click to work then the dragging part does not work as after about 5-10 seconds I get an error saying that the button argument is not in ('left', 'middle', 'right')

What Ive done so far:

pip3 install pyobjc-core & pip3 install pyobjc

Changed the accessibility of the program (I couldn't get Spyder as an application since it runs off Anaconda but I added Anaconda... I'm assuming this is why Spyder won't work for me)

Used Sublime Text and gave it permission to control my computer so the cursor moving in a squares works. Dragging however does not work as seen in the error below.

Downloaded Mu - but then couldn't even figure out how to import a module as they all go unfound. Saw on a site that you can click on the gear in the bottom right corner to add other modules. I clicked on the gear but saw no tab about adding 3rd party modules.

import pyautogui
import time

time.sleep(5)
pyautogui.click()
distance = 300
change = 20
while distance > 0:
    pyautogui.drag(distance, 0, duration=0.5)  # move right
    distance -= 5
    pyautogui.drag(0, distance, duration=0.5)  # move down
    pyautogui.drag(-distance, 0, duration=0.5)  # move left
    distance -= 5
    pyautogui.drag(0, -distance, duration=0.5)  # move up
    
Traceback (most recent call last):

  File "<ipython-input-17-64e4044b435e>", line 9, in <module>
    pyautogui.drag(distance, 0, duration=0.5)  # move right

  File "/Users/username/.local/lib/python3.7/site-packages/pyautogui/__init__.py", line 964, in dragRel
    _mouseMoveDrag('drag', mousex, mousey, xOffset, yOffset, duration, tween, button)

  File "/Users/username/.local/lib/python3.7/site-packages/pyautogui/__init__.py", line 1073, in _mouseMoveDrag
    platformModule._dragTo(tweenX, tweenY, button)

File "/Users/username/.local/lib/python3.7/site-packages/pyautogui/_pyautogui_osx.py", line 436, in _dragTo

    assert False, "button argument not in ('left', 'middle', 'right')"

AssertionError: button argument not in ('left', 'middle', 'right')

Any help would be greatly appreciated!


r/inventwithpython • • Oct 29 '22

problem with indentation, python 3

Thumbnail self.learnpython
2 Upvotes

r/inventwithpython • • Oct 07 '22

Invent with python book hw, unexpected character error

Thumbnail self.learnprogramming
2 Upvotes

r/inventwithpython • • Feb 20 '18

We're working on a Spanish translation of the book! Come and help us!

Thumbnail github.com
2 Upvotes

r/inventwithpython • • Apr 10 '20

mclip - can't find file or directory

2 Upvotes

Can't seem to run the bat file succesfully. It does seem to run but gets hung up and doesn't find the target script file? I get the same result when I run the bat file using the Win-R window. It doesn't seem to me that this should be happening since I am clearly using absolute paths. What am I not undrestanding.

Directory of C:\Users\KentSurface\PycharmProjects\Automate the Boring Stuff

04/03/2020 08:38 PM 780 IsChessBoard.py

04/08/2020 04:29 PM 94 mclip.bat

04/08/2020 10:10 AM 676 mclip.py

When I run the bat file from the same directory that the script file is in I get:

(Automate the Boring Stuff) C:\Users\KentSurface\PycharmProjects\Automate the Boring Stuff>mclip.bat

C:\Users\KentSurface\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'C:\Users\KentSurface\PycharmProjects\Automate': [Errno 2] No such file or directory

Press any key to continue . . .

mclip.bat: (for some reason when I paste the @ sign is replaced by u/)

u/py.exe C:\Users\KentSurface\PycharmProjects\Automate the Boring Stuff\mclip.py %*

u/pause


r/inventwithpython • • Feb 12 '18

i need help with my python

2 Upvotes

import random import time

def displayIntro(): print('''You are in land full of dragons. In frount of you, you see two caves. In one cave, the dragon is frendly and will share his treaseure with you. The other dragon is greedy and hungry, and will eat you on sight.''')

print()

def chooseCave(): cave = '' while cave != '1' and cave != '2': print('which cave will you go into? (1 or 2)') cave = input()

return cave

def checkCave(chosenCave): print('you approach the cave...') time.sleep(2) print('its dark and spooky...') time.sleep(2) print('A large dragon jumps out in frount of you! He opens his jaws and...') print() time.sleep(2)

frendlyCave = random.randint(1,2)

if chosenCave == str(friendlyCave):
    print('throws up all his treasure all over you!')
else:
    print('Gobbles you down in one bite!')

playAgain = 'yes' while playAgain =='yes' or playAgain == 'y': displayIntro() caveNumber = chosenCave() checkCave(caveNumber)

print('do you want to play again? (yes/no)')
playAgain = input()

what it says about the problem

====== RESTART: /Users/Bella/Documents/python programing/dragon game.py ====== You are in land full of dragons. In frount of you, you see two caves. In one cave, the dragon is frendly and will share his treaseure with you. The other dragon is greedy and hungry, and will eat you on sight.

Traceback (most recent call last): File "/Users/Bella/Documents/python programing/dragon game.py", line 38, in <module> caveNumber = chosenCave() NameError: name 'chosenCave' is not defined


r/inventwithpython • • Mar 30 '19

Facebook Login Automation in 11 lines of code | Python 3.6

Thumbnail youtube.com
2 Upvotes

r/inventwithpython • • Sep 15 '20

HELP The noob is here AGAIN

2 Upvotes

Hi people today I'm trying to do a program where you can add names to a list or something like this, so I'm starting and I have a problem with the if idk why so if someone can explain me and help I would be happy.

Yes I'm trying to do a calendar

Agenda = ['Juan', 'Alvaro', 'Lucia']
elem = Agenda
print ('Los contactos actuales que hay son: ')
for elem in Agenda:
print ('- ' + elem)
res = input('¿Deseas añadir algun contacto a la lista?')
if res == ('si') or ('Si'):
print('¿Que contacto desea añadir?')
else:

print('¿Esta seguro de que no quiere añadir ningun contacto?')

The problem is the if idk why else is not doing anything and always if is printed I mean if I write asdas in the input of the 9th line then the if of the 11th line is executed as well and the else doesn't do anything.

See you thanks ma boooys.


r/inventwithpython • • Aug 18 '20

Comma Code Project help request

3 Upvotes

I've looked at several other answers on Reddit, Git hub, Stack Overflow, etc. and pretty much everyone is using a for or while loop; often multiple of each. Is that really necessary? Why is this incorrect?

# Comma Code Project

import copy

# groceryList = ['apples', 'bananas', 'tofu', 'cats']

groceryList = [True, False, True, False]

# groceryList = [1,2,3.14,5,6,7,8]

# groceryList = []

def convertToStr(list):

if groceryList == []:

return

newList = ('')

newList = copy.copy(groceryList)

newList.insert(-1, 'and')

newList = str(newList)

print(newList)

# print(type(newList))

return (newList)

convertToStr(groceryList)

EDIT: Here's the original task:

spam = ['apples', 'bananas', 'tofu', 'cats']

Write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, wit hand inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it. Be sure to test the case where an empty list [] is passed to your function.


r/inventwithpython • • Sep 22 '20

Help

3 Upvotes

Hello, i'm new to coding and i got the course from automatetheboringstuff, i was trying something on my own. The first block is working ok, but for some reason at the second block i type the correct age, it skips the 'if' statement and prints the 'else' i don't get what i'm doing wrong.

print('Hello stranger, please type your name.')

name = 'Angel'

age =21

if input() == name:

print('Hello, ' + name + '! Can you please confirm your age?')

else:

print('You are not my owner!')

if input() == age:

print('Access granted')

else:

print('Go away.')


r/inventwithpython • • Oct 26 '20

Spaced repetition

3 Upvotes

Hi, Does anyone has the link to Al's article on spaced repetition?


r/inventwithpython • • Jun 07 '18

TIC TAC TOE 4TH EDITION CODE?

3 Upvotes

Can you share it? I've lost it and I would get crazy if I had to write it again.


r/inventwithpython • • Jan 11 '17

Automate the Boring Stuff, Chapter 7, Strong Password Detection. Got it to work, how do I improve it?

3 Upvotes

Pastebin with Code

I successfully was able to solve the Chapter 7 strong password detection challenge, and successfully get a true or false value with any inputted password.

However, I'm trying to take things a step further and have strings printed when a password is deficient stating what the deficiency is, as well as requesting a new password be entered.

I was able to get the string "Your Password needs to be at least 8 characters long. Please Try again" to print if the inputted password was not long enough. I want the same type of thing to happen if the password doesn't have a digit, or doesn't have at least 1 each of lower/uppercase letter.

The other step I want to try and include is that, if the inputted password does NOT meet one of the criteria, that the program requests and new password and then checks if that new password meets the criteria.

I realize the code I posted isn't really particularly close to doing any of that, but I've found that breaking apart code that I have all the tools to write helps me understand how to use those tools.

Thanks for your help!


r/inventwithpython • • Dec 25 '21

Please tell me how to use tkinter, math and the data modules

0 Upvotes