Friday, June 28, 2024

Clue Game

Here is a one day practice Clue game. It's not multiplayer yet, and I may never add that. Just for practice. Can be tested at https://www.programiz.com/python-programming/online-compiler/ (Remove the 3 lines of "stuff" on the left on their site, or it might not run properly. Also, the site seems to time out, but it's the only one I see that can run this one.)


import random

guess = "wrong"
progress_array = ["person", "place", "weapon"]
progress_counter = 2
progress_person = "no"
progress_place = "no"
progress_weapon = "no"
firstguess = 2
people = ("Colonel Mustard", "Miss Scarlet", "Mr. Green", "Mrs. Peacock", "Mrs. White", "Professor Plum")
places = ("hall", "lounge", "dining room", "kitchen", "ballroom", "conservatory", "billiard room", "library", "study")
weapons = ("candlestick", "dagger", "revolver", "lead pipe", "wrench", "rope")

people_random = (random.randint(0,5))
places_random = (random.randint(0,8))
weapons_random = (random.randint(0,5))
shuffle = (people [people_random], places [places_random], weapons [weapons_random])

#print (shuffle)

print ("List of people: Colonel Mustard, Miss Scarlet, Mr. Green, Mrs. Peacock, Mrs. White, Professor Plum\n")
print ("List of places: hall, lounge, dining room, kitchen, ballroom, conservatory, billiard room, library, study\n")
print ("List of weapons: candlestick, dagger, revolver, lead pipe, wrench, rope")
print ("---------------------------------------\n")


while guess == ("wrong"):
    
    if progress_person != "yes":
        person_guess = input ("Make your guess of the person: ")
    if progress_place != "yes":
        place_guess = input ("Make your guess of the place: ")
    if progress_weapon != "yes":
        weapon_guess = input ("Make your guess of the weapon: ")

    if progress_counter == 3:    

        if person_guess == (people [people_random]) and progress_person != "yes":
            print ("\nYou got the person right.\n")
            progress_person = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1
            progress_array.pop(firstguess-2)
        if progress_person == "yes":
            firstguess = firstguess - 1
        if place_guess == (places [places_random]) and progress_place != "yes":
            print ("\nYou got the place right.\n")
            progress_place = "yes"
            progress_counter = progress_counter - 1
            progress_array.pop(firstguess-1)
        if progress_place == "yes" and progress_person != "yes":
            firstguess = firstguess - 1
        if weapon_guess == (weapons [weapons_random]) and progress_weapon != "yes":
            print ("\nYou got the weapon right.\n")
            progress_weapon = "yes"
            progress_counter = progress_counter - 1
            progress_array.pop(firstguess)
        if progress_weapon == "yes":
            firstguess = firstguess - 1
    else:

        if person_guess == (people [people_random]) and progress_person != "yes":
            print ("\nYou got the person right.\n")
            progress_person = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1
        if place_guess == (places [places_random]) and progress_place != "yes":
            print ("\nYou got the place right.\n")
            progress_place = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1
        if weapon_guess == (weapons [weapons_random]) and progress_weapon != "yes":
            print ("\nYou got the weapon right.\n")
            progress_weapon = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1   
        
    if (progress_person == "yes" and progress_place == "yes" and progress_weapon == "yes"):
        print ("\n****YOU SOLVED IT!!!****")
        print (people [people_random], "did it in the", places [places_random], "with a", weapons [weapons_random])
        guess = "solved"
    else:
        tryagain = 2
        print ("Try Again\n")

Saturday, June 22, 2024

Rock Paper Scissors (with adjustments)

I forgot to put the spellchecker conditional back in, and when I did I realized "elif" had to be used. Otherwise, it would skip in the array and end with less results instead of 5.

Repeating the post with the adjustment.

Code can be tested at https://www.programiz.com/python-programming/online-compiler/ (Remove the 3 lines of "stuff" on the left on their site, or it might not load properly.)

First attempt at rock, paper, scissors in Python. I was inspired by this post, https://bsky.app/profile/coding.bsky.social/post/3kq7rtxldn42v (Remove the 3 lines of "stuff" on the left on their site, or it might not run properly.)

 

import random
#import numpy/itertools later (install, run pip, code later)

#a = 1
turnresults = []
choiceplayer = []
scoreplayer = 0
opponentresults = 0
#Do 128 later, 5 for now
while (len(turnresults)<5):
    #for a in range(1, 5):
    #Have to reindent if using for
    choice = input("Enter rock, paper, or scissors: ")
    opponent = (random.randint(1,3))

    if (choice == "rock") and (opponent == 2):
        print("Rock loses to paper \n")
        opponentresults = opponentresults + 1        
    if (choice == "rock") and (opponent == 3):
        print("Rock wins to scissors \n")
        scoreplayer = scoreplayer + 1        
    if (choice == "paper") and (opponent == 1):
        print("Paper wins to rock \n")
        scoreplayer = scoreplayer + 1  
    if (choice == "paper") and (opponent == 3):
        print("Paper loses to scissors \n")
        opponentresults = opponentresults + 1        
    if (choice == "scissors") and (opponent == 1):
        print("Scissors loses to rock \n")
        opponentresults = opponentresults + 1
    if (choice == "scissors") and (opponent == 2):
        print("Scissors wins to paper \n")
        scoreplayer = scoreplayer + 1

    #opponent = str(opponent)
    #choice = str(choice)

    if (choice == "rock" and opponent == 1) or (choice == "paper" and opponent == 2) or (choice == "scissors" and opponent == 3):        
       print("SAME!! Try again. \n")
       #print ("turnresults = ", turnresults)
       #print ("SAME / Turn results = ", turnresults)
    elif (choice != "rock" and choice != "paper" and choice != "scissors"):
       print("Type rock, paper, or scissors (lower case). \n")

    
        
    else:
        choiceplayer.append(choice)
        turnresults.append(opponent)
        #print ("opponent's choices: ", turnresults)
        #print ("your choices: ", choiceplayer)
        #print (turnresults)
        print ("Score: YOU ", scoreplayer, " - THEM ", opponentresults)
        

if (scoreplayer > opponentresults):
    print ("***YOU WIN!!!***")
else:
    print ("***YOU LOSE!!!***")
               
        
    #print (len(turnresults))

    
    #if (choice == "rock" or choice == "paper" or choice == "scissors"):
        #print("choice is: " + choice)
        #opponent = (random.randint(1,3))
        #opponent = str(opponent)
        #turnresults.append(opponent)
        #print (turnresults)
    #else:
        #print("Type \"rock, paper, or scissors:\"")
        #choice = input()
        #turnresults.append(opponent)
        #print (turnresults)
        #a=a+1 #Doesn't work to get 5 turn results




#It doesn't complete 5 successful turn results when the for loop is used
 

 

Friday, June 21, 2024

Rock Paper Scissors

**See 6/22 post for adjustments.**

Code can be tested at https://www.programiz.com/python-programming/online-compiler/ (Remove the 3 lines of "stuff" on the left on their site, or it might not run properly.)

First attempt at rock, paper, scissors in Python. I was inspired by this post, https://bsky.app/profile/coding.bsky.social/post/3kq7rtxldn42v

 

import random
#import numpy/itertools later (install, run pip, code later)

#a = 1
turnresults = []
choiceplayer = []
scoreplayer = 0
opponentresults = 0
#Do 128 later, 5 for now
while (len(turnresults)<5):
    #for a in range(1, 5):
    #Have to reindent if using for
    choice = input("Enter rock, paper, or scissors: ")
    opponent = (random.randint(1,3))

    if (choice == "rock") and (opponent == 2):
        print("Rock loses to paper \n")
        opponentresults = opponentresults + 1        
    if (choice == "rock") and (opponent == 3):
        print("Rock wins to scissors \n")
        scoreplayer = scoreplayer + 1        
    if (choice == "paper") and (opponent == 1):
        print("Paper wins to rock \n")
        scoreplayer = scoreplayer + 1  
    if (choice == "paper") and (opponent == 3):
        print("Paper loses to scissors \n")
        opponentresults = opponentresults + 1        
    if (choice == "scissors") and (opponent == 1):
        print("Scissors loses to rock \n")
        opponentresults = opponentresults + 1
    if (choice == "scissors") and (opponent == 2):
        print("Scissors wins to paper \n")
        scoreplayer = scoreplayer + 1

    #opponent = str(opponent)
    #choice = str(choice)

    if (choice == "rock" and opponent == 1) or (choice == "paper" and opponent == 2) or (choice == "scissors" and opponent == 3):        
        print("SAME!! Try again. \n")
        #print ("turnresults = ", turnresults)
        #print ("SAME / Turn results = ", turnresults)
        
    else:
        choiceplayer.append(choice)
        turnresults.append(opponent)
        ##print ("opponent's choices: ", turnresults)
        ##print ("your choices: ", choiceplayer)
        ##print (turnresults)
        print ("Score: YOU ", scoreplayer, " - THEM ", opponentresults)

if (scoreplayer > opponentresults):
    print ("***YOU WIN!!!***")
else:
    print ("***YOU LOSE!!!***")
               
        
    #print (len(turnresults))

    
    #if (choice == "rock" or choice == "paper" or choice == "scissors"):
        #print("choice is: " + choice)
        #opponent = (random.randint(1,3))
        #opponent = str(opponent)
        #turnresults.append(opponent)
        #print (turnresults)
    #else:
        #print("Type \"rock, paper, or scissors:\"")
        #choice = input()
        #turnresults.append(opponent)
        #print (turnresults)
        #a=a+1 #Doesn't work to get 5 turn results




#It doesn't complete 5 successful turn results when the for loop is used