r/inventwithpython • • Apr 15 '19

I just finished chapter 5 of Invent Your Own Computer Games With Python and I decided to try to apply what I had learned. So I made this game. Thoughts?

1 Upvotes

If you prefer to read it on pastebin, here's the link. https://pastebin.com/qzdPU423

import time
slot = ['BAM!', 'click.', 'click.', 'click.', 'click.', 'click.']
dieMessage = ['You DIED! Thank goodness!', 'Good riddance.', 'My Condolences. You failed.', 'I will tell your parents that you died with honor.', 'I will tell your parents that you died for nothing.', 'Will somebody clean this up?']
surviveMessage = ['YEEEHAW! I ain\'t gon die today!', 'Thank heavens! You didn\'t get your brains blown out!', 'You have not died... YET.', 'This is getting intense.', 'Dang.', 'Maybe next time...']
def welcome():
    print('Welcome to Russian Roulette!')
    time.sleep(2)
    global peopleCount
    peopleCount = input('How many people are playing? (2-6): ')
    peopleCount = int(peopleCount)
    while int(peopleCount) < 2 or int(peopleCount) > 6:
        print('You must have at least 2 people and at most 6 people to play!')
        time.sleep(2)
        peopleCount = input('How many people are playing? (2-6): ')
    else:
        print('Please state your friends names, one at a time')
        if int(peopleCount) > 1:
            global person1
            person1 = input('Person #1: ')
            global person2
            person2 = input('Person #2: ')
            global choosePerson
            choosePerson = [person1, person2]
            if int(peopleCount) > 2:
                global person3
                person3 = input('Person #3: ')
                choosePerson = [person1, person2, person3]
                if int(peopleCount) > 3:
                    global person4
                    person4 = input('Person #4: ')
                    choosePerson = [person1, person2, person3, person4]
                    if int(peopleCount) > 4:
                        global person5
                        person5 = input('Person #5: ')
                        choosePerson = [person1, person2, person3, person4, person5]
                        if int(peopleCount) > 5:
                            global person6
                            person6 = input('Person #6: ')
                            choosePerson = [person1, person2, person3, person4, person5, person6]
            global choosePersonNum
            choosePersonNum = 10
            if int(peopleCount) == 2:
                print('Welcome, ' + person1 + ' and '  + person2 + '!')
                choosePersonNum = 10
                choosePersonNum = random.randint(0, 1)
            if int(peopleCount) == 3:
                print('Welcome, ' + person1 + ', '  + person2 + ', and ' + person3 + '!')
                choosePersonNum = 10
                choosePersonNum = random.randint(0, 2)
            if int(peopleCount) == 4:
                print('Welcome, ' + person1 + ', '  + person2 + ', ' + person3 + ', and '  + person4 + '!')
                choosePersonNum = 10
                choosePersonNum = random.randint(0, 3)
            if int(peopleCount) == 5:
                print('Welcome, ' + person1 + ', '  + person2 + ', ' + person3 + ', '  + person4 + ', and ' + person5 + '! ')
                choosePersonNum = 10
                choosePersonNum = random.randint(0, 4)
            if int(peopleCount) == 6:
                print('Welcome, ' + person1 + ', '  + person2 + ', ' + person3 + ', '  + person4 + ', ' + person5 + ', and ' + person6 + '! ')
                choosePersonNum = 10
                choosePersonNum = random.randint(0, 5)
def play():
    for i in range(7):
        global choosePersonNum
        if peopleCount == int(2):
            if i == 0:
                print('Ok! Let\'s begin!')
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 5)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(4)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(4)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 2:
                        choosePersonNum = 0
            if i == 1:
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 4)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(4)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(4)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 2:
                        choosePersonNum = 0
            if i == 2:
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 3)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(4)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(4)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 2:
                        choosePersonNum = 0
            if i == 3:
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 2)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 2:
                        choosePersonNum = 0
            if i == 4:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 1)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 2:
                        choosePersonNum = 0
            if i == 5:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 0)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 0)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 2:
                        choosePersonNum = 0
        if peopleCount == 3:
            if i == 0:
                 print('Ok! Let\'s begin!')
                 time.sleep(2)
                 print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                 time.sleep(2)
                 number = random.randint(0, 5)
                 print (slot[number])
                 time.sleep(2)
                 if slot[number] == 'BAM!':
                     dieMessageNum = random.randint(0, 5)
                     print(dieMessage[dieMessageNum])
                     time.sleep(2)
                     break
                 else:
                     surviveMessageNum = random.randint(0, 5)
                     print(surviveMessage[surviveMessageNum])
                     time.sleep(2)
                     choosePersonNum = choosePersonNum + 1
                     if choosePersonNum == 3:
                         choosePersonNum = 0
            if i == 1:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 4)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 3:
                        choosePersonNum = 0
            if i == 2:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 3)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 3:
                        choosePersonNum = 0
            if i == 3:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 2)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 3:
                        choosePersonNum = 0
            if i == 4:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 1)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 3:
                        choosePersonNum = 0
            if i == 5:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 0)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 3:
                        choosePersonNum = 0
        if peopleCount == 4:
            if i == 0:
                 print('Ok! Let\'s begin!')
                 time.sleep(2)
                 print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                 time.sleep(2)
                 number = random.randint(0, 5)
                 print (slot[number])
                 time.sleep(2)
                 if slot[number] == 'BAM!':
                     dieMessageNum = random.randint(0, 5)
                     print(dieMessage[dieMessageNum])
                     time.sleep(2)
                     break
                 else:
                     surviveMessageNum = random.randint(0, 5)
                     print(surviveMessage[surviveMessageNum])
                     time.sleep(2)
                     choosePersonNum = choosePersonNum + 1
                     if choosePersonNum == 4:
                         choosePersonNum = 0
            if i == 1:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 4)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 4:
                        choosePersonNum = 0
            if i == 2:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 3)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 4:
                        choosePersonNum = 0
            if i == 3:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 2)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 4:
                        choosePersonNum = 0
            if i == 4:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 1)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 4:
                        choosePersonNum = 0
            if i == 5:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 0)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 4:
                        choosePersonNum = 0
        if peopleCount == 5:
            if i == 0:
                 print('Ok! Let\'s begin!')
                 time.sleep(2)
                 print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                 time.sleep(2)
                 number = random.randint(0, 5)
                 print (slot[number])
                 time.sleep(2)
                 if slot[number] == 'BAM!':
                     dieMessageNum = random.randint(0, 5)
                     print(dieMessage[dieMessageNum])
                     time.sleep(2)
                     break
                 else:
                     surviveMessageNum = random.randint(0, 5)
                     print(surviveMessage[surviveMessageNum])
                     time.sleep(2)
                     choosePersonNum = choosePersonNum + 1
                     if choosePersonNum == 5:
                         choosePersonNum = 0
            if i == 1:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 4)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 5:
                        choosePersonNum = 0
            if i == 2:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 3)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 5:
                        choosePersonNum = 0
            if i == 3:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 2)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 5:
                        choosePersonNum = 0
            if i == 4:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 1)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 5:
                        choosePersonNum = 0
            if i == 5:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 0)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 5:
                        choosePersonNum = 0
        if peopleCount == 6:
            if i == 0:
                 print('Ok! Let\'s begin!')
                 time.sleep(2)
                 print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                 time.sleep(2)
                 number = random.randint(0, 5)
                 print (slot[number])
                 time.sleep(2)
                 if slot[number] == 'BAM!':
                     dieMessageNum = random.randint(0, 5)
                     print(dieMessage[dieMessageNum])
                     time.sleep(2)
                     break
                 else:
                     surviveMessageNum = random.randint(0, 5)
                     print(surviveMessage[surviveMessageNum])
                     time.sleep(2)
                     choosePersonNum = choosePersonNum + 1
                     if choosePersonNum == 6:
                         choosePersonNum = 0
            if i == 1:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 4)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 6:
                        choosePersonNum = 0
            if i == 2:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 3)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 6:
                        choosePersonNum = 0
            if i == 3:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 2)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 6:
                        choosePersonNum = 0
            if i == 4:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 1)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 6:
                        choosePersonNum = 0
            if i == 5:
                time.sleep(2)
                print('It\'s ' + choosePerson[choosePersonNum] + 's turn')
                time.sleep(2)
                number = random.randint(0, 0)
                print (slot[number])
                time.sleep(2)
                if slot[number] == 'BAM!':
                    dieMessageNum = random.randint(0, 5)
                    print(dieMessage[dieMessageNum])
                    time.sleep(2)
                    break
                else:
                    surviveMessageNum = random.randint(0, 5)
                    print(surviveMessage[surviveMessageNum])
                    time.sleep(2)
                    choosePersonNum = choosePersonNum + 1
                    if choosePersonNum == 6:
                        choosePersonNum = 0
playAgain = 'y'
while playAgain == 'yes' or playAgain == 'Yes' or playAgain == 'y':
    welcome()
    play()
    print('Would you like to play again?')
    playAgain = input()

r/inventwithpython • • Apr 21 '20

python coding

0 Upvotes

I'm really confused about the Tkinter when popping up a message and using a txt file with a Tkinter. I don't know how to combine both and make it read it.

animal.txt (is the file):

Cheetah,Mammal,Carnivore

Caiman,Reptile,Carnivore

Bear,Mammal,Omnivore

Elk,Mammal,Herbivore

Turtle,Reptile,Omnivore

Lizard,Reptile,Omnivore

Bobcat,Mammal,Carnivore

Yak,Mammal,Herbivore

Ibis,Bird,Carnivore

Eagle,Bird,Carnivore

Racoon,Mammal,Omnivore

Emu,Bird,Omnivore

Llama,Mammal,Herbivore

Parrot,Bird,Herbivore

Iguana,Reptile,Herbivore

Ermine,Mammal,Carnivore

Crocodile,Reptile,Carnivore

program extra work for practice

Second part of practice

last part

output what practice should look like

sorry the pics wouldn't all fit on one page


r/inventwithpython • • Apr 30 '24

Beginner Programmer using Invent Your Own Video Games with Python

0 Upvotes

beginner programmer here, so I'm having trouble running a simple code that displays "Hello World" on another window when the program running successfully, ive compared it to the book and still nothing i am running it through Pycharm book is Invent Your Own Computer Games With Python (Fig.17-1)pg.257


r/inventwithpython • • Nov 27 '22

source code for Invent Your Own Computer Games

0 Upvotes

For the book ( Invent Your Own Computer Games ), Should I pay for the source code, or its free,

if it's free plz I need the URL for the source code

best


r/inventwithpython • • Sep 08 '19

Question about the project in book "Automate the Boring Stuff with Python"

Post image
1 Upvotes

r/inventwithpython • • Jun 10 '24

How is everyone? I just started reading Invent Your Own Computer Games with Python, 4th Edition.

2 Upvotes

(This photo is not me irl btw, found it when i googled "waving picture")
Anyways, just me saying hello to the community, i doubt anyone is gonna care anyways. :D


r/inventwithpython • • Jan 12 '19

Coding for noobs

2 Upvotes

Is there a specific reddit for people who want to learn how to code?


r/inventwithpython • • Apr 19 '17

awful book for reading

0 Upvotes

The book is good, but as always, reading it is awful when authors emulate the IDLE putting these symbols ">>" to write codes examples on the book, it will be good if the book is written in the similar formatting as Python "Crash Course A Hand-on" book , without those annoying symbols ">>". Just my opinion!


r/inventwithpython • • Feb 05 '16

Tic Tac Toe

0 Upvotes

I'm trying to go a little deeper with creating a tic-tac-toe game. Here is the code for the game I'm trying to create, and the issue I'm having is between lines 38 and 57.

For some reason, I can't come up with anything that makes Python correctly evaluate a winner. As it stands, whoever players square 3 is the winner. I realize that the code as it's written is likely saying "the value of the theBoard[1] times theBoard[2] and theBoard[3] equals X, I see X in spot 3, therefore we have a winner," But I don't know how I would ask Python to independently check the values of each square for matching values.

Would appreciate any help people have!


r/inventwithpython • • Feb 06 '16

Trying to gift Automate, while getting the most bucks to Al

0 Upvotes

Hey all,

I was completely new to programming before taking Al's "Automate the Boring Stuff with Python". In a nut shell: I adored the course, and, I want to get my older brother (who's birthday is coming soon) as into it as I am. I want get him a copy of the physical book but I also think Al's video lectures were the best part of the course. Does anyone know the best way to gift "the complete package" while also making sure most of the money goes to Al (instead of randoPublisher)?

Also, if someone knows how to cue him in to my inquiry, maybe Al is the best person to ask. Time is of the essence!!!!

-Mike (A math teacher who can code)


r/inventwithpython • • Oct 08 '21

Can anyone me code this question?

4 Upvotes

Craps is a unique casino game played with 2 dice that is often shown in movies.  You will create a program that simulates a game of craps based on the following rules of the game:

On the first roll:- if you roll a 7 or 11,  you win!- if you roll a 2 or 12,   you lose - if you roll a 3,4,5,6,8,9 or 10 you rolled "point" and you must roll again

On subsequent rolls (any roll after the first roll)- if you roll your point, you win!- if you roll 7 or 11, you lose- if you roll anything else, this becomes your new point and you must roll again

Your user output will indicate what the user rolls throughout the game as it is played, in addition to win/lose/play again messages.


r/inventwithpython • • Oct 31 '20

python programming

4 Upvotes

Use library tools_4211 to cut a random set Z of 35 objects, with the respective labels stored in Y. Hint: To find the number of elements of a 1D array, e.g., Labels, use len(Labels).


r/inventwithpython • • Apr 10 '16

Can someone walk me through Chapter 7's Phone Number and Email Address Extractor Problem?

0 Upvotes

I'm lost as to how this should be appearing - is each part a separate file? Also, for the part 3., when you are finding all matches on clipboard, for the part that goes " phoneRegex = re.compile(r'''( --snip-"

what is the end part of this?

Any help would be appreciated.


r/inventwithpython • • May 03 '20

Guess the game

0 Upvotes

I WANT TO KNOW IF THIS IS RIGHT OR WRONG

#MY PROGRAM

#Guess the number game.

import random, sys

secretNumber = random.randint(1,20)

print('I am thinking of a number between 1 and 20.')

#Ask the player to guess 6 times

for guessTaken in range(1,7):

guess = int(input('Take a guess.\n'))

if guess < secretNumber:

print('Your guess is too low.')

elif guess > secretNumber:

print('Your guess is too high.')

elif guess == secretNumber:

print('Good job! You guessed the number in ' + str(guessTaken) + ' guesses!')

sys.exit()

print('Nope.The number I was thinking of was ' + str(secretNumber))


r/inventwithpython • • May 03 '20

Have I found my first bug? (for loop with enumerate function)

0 Upvotes

Hiya.

I'm using Python 3.8 64-bit on Win10, coding in Mu, and have been driven up the wall trying to code something simple for Al's Coin Toss challenge at the end of chapter 4.

So I was taking it line at a time, printing results to see where my error was. Here's an example of one of the loops I used to test:

letters = 'abcdefghijklmnopqrstuvwxyz'
experiment = list(letters)
for index, item in enumerate(experiment):
    previousItem = experiment[index - 1]
    nextItem = experiment[index+1]
    print(index)
    print(item)
    print(previousItem)    
    print(nextItem)

The first two iterations print:

0

a

z

b

1

b

a

c

which is what I would have expected.

However, when I try to start the loop from index 1 like so:

letters = 'abcdefghijklmnopqrstuvwxyz'
experiment = list(letters)
for index, item in enumerate(experiment, start = 1):
    previousItem = experiment[index - 1]
    nextItem = experiment[index+1]
    print(index)
    print(item)
    print(previousItem)    
    print(nextItem)

The result is:

1

a

a

c

2

b

b

d

So even though index is correctly starting at 1, the item given is still experiment[0], not experiment[1]. I tried this with enumerate(... start=2) but again, item == 'a' (== experiment[0]) not the item at the correct index.

If I replace print(item) with print(experiment[index]) I get the correct result, but why is it that the item in the iteration doesn't match the index? Isn't that the whole point of the enumerate function? or have I missed something?

Looking forward to a response! This problem has been confusing me for days now before I located it!

duck


r/inventwithpython • • Jul 01 '20

Hello

4 Upvotes

Hello Everyone I'm new here, and i just wanted to say Hi!!


r/inventwithpython • • Mar 19 '20

Problem with TaTeTi Game!

1 Upvotes

r/inventwithpython • • Apr 30 '16

Chapter 16 sending email. How do you locate the SMTP server domain name for hostgator webmail?

1 Upvotes

I'm at Chapter 16 and I'm trying to send emails through python. I tried it with my gmail account and it works. However, I wish to send emails from my webmail that has my domain name in it.

My web host is hostgator.

I tried to set smtpObj as such (i've replaced my domain name as 'mydomainname' for privacy issue):

smtpObj = smtplib.SMTP('smtp.mydomainname.com', 587)

but it gave me an error:

Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> smtpObj = smtplib.SMTP('smtp.mydomainname.com', 587) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 251, in init (code, msg) = self.connect(host, port) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 335, in connect self.sock = self._get_socket(host, port, self.timeout) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 306, in _get_socket self.source_address) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 693, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 8] nodename nor servname provided, or not known

I tried going on hostgator to find out but to no avail :(


r/inventwithpython • • Jun 29 '18

Nostarch book cover becoming unglued

1 Upvotes

Hi:

I enjoy your publications and intend to buy more.

Just wanted to alert you to a problem I'm having with "How to automate the boring stuff ..."

Not sure what your affiliation with nostarch is ..

Bought on amazon  (great book) but the glue is becoming soft and not holding the cover on.

(office temperature is around 70-85 F)

I have reattached it and I'm going t try and use superglue.

I tried to visit nostarch website to let them know but they are trying to install some rogue chrome extension, so no F&*%$# way :)

Just wanted to let you know

Best


r/inventwithpython • • Aug 18 '16

"Automate the Boring Stuff" site down?

1 Upvotes

I'm loving the course, but I've tried to continue today and the website appears to be down. Can anyone confirm?


r/inventwithpython • • Sep 22 '16

[hacking]Where're the exercices of hacking?

0 Upvotes

Where are the practice exercices of Hacking Secret Codes, from chapter 13 to 24? I don't find them anywhere


r/inventwithpython • • Dec 08 '17

Problem decrypting messages

1 Upvotes

Hello, I keep getting the error int too large to convert to c long whenever I run the decryption function. I checked my code with what was provided and it was the same. Kindly assist


r/inventwithpython • • Jul 08 '15

Too many playAgains in chapter 9

1 Upvotes

I just finished chapter 9 and i was confused about why are we asking the player to play 2 times, the first was at line 100 when defining play again, and the second was at line 139


r/inventwithpython • • Jan 21 '23

PyPi Pip Installation

1 Upvotes

This may or may not be the best place to ask this question, but I recently installed Python 3.11 (latest) and using pip install automateboringstuff2ndedition gives numerous warnings of outdated installer dependencies. It also seems to not like the version of pillow that is outlined from automateboringstuff2ndedition 1.0.3. As an alternative I installed Pillow 9.4.0, but when I reran the 2nd edition pip install, I got a notice that it uninstalled Pillow 9.4.0. As a test then, I went to IDLE for 3.11 and import PIL worked just fine (no errors). Am I missing something? Should the 2nd edition pip installer be used for 3.11?

Pillow error:

RuntimeWarning: Pillow 9.0.0 does not support Python 3.11 and does not provide prebuilt Windows binaries. We do not recommend building from source on Windows.

Deprecation error (note I found this on another install as well, so it may not be 100% accurate to the 2nd edition pip install):

DEPRECATION: future is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for future ... done DEPRECATION: pefile is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559

r/inventwithpython • • Sep 21 '17

Problem with Tic Tac Toe game.

1 Upvotes

I'm getting a invalid syntax error in the Tic Tac Toe game. Line 50. I've typed it exactly like the book and it's the same in the dif tool. I'm using the 3rd edition web download book.

def isWinner(bo, le):

Too bad when you get an error, it didn't tell you how to fix it.