What's your favorite number? 16
16 is a very cool number!
Current Fruits List ['Apple', 'Banana']
Please enter a fruit name:
Strawberry
Updated Fruits List ['Apple', 'Banana', 'Strawberry']
{'Lionel Messi': 'FC Barcelona', 'Christiano Ronaldo': 'Real Madrid', 'Neymar Jr': 'PSG'}
FC Barcelona
3
Pick a number lower of higher than 10: 10
You couldn't follow simple directions, bad job
#Program with a Function to perform mathematical and/or a statistical calculations, contains a condition
inp = input("Would you like to add, subtract, multiply, or divide two numbers today?")
#If the user decides they want to add two number, this if statement will run
if inp == "Add" or inp == "add":
x = int(input("Pick the first number you would like to add: "))
y = int(input("Pick the second number you would like to add: "))
z = x + y
print("Your answer is", z)
#If the user decides they want to subtract two number, this if statement will run
elif inp == "Subtract" or inp == "subtract":
a = int(input("Pick the first number you would like to subtract: "))
b = int(input("Pick the second number you would like to subtract: "))
c = a - b
print("Your answer is", c)
elif inp == "Multiply" or inp == "multiply":
a = int(input("Pick the first number you would like to multiply: "))
b = int(input("Pick the second number you would like to multiply: "))
c = a * b
print("Your answer will be", c)
elif inp == "Divide" or inp == "divide":
a = int(input("Pick the first number you would like to divide: "))
b = int(input("Pick the second number you would like to divide: "))
c = a/b
print("Your answer is", c)
else:
print("Please follow the simple directions given")
Please follow the simple directions given
import random
class RockPaperScissors:
"""
Class to handle an instance of a Rock-Paper-Scissors game
with unlimited rounds.
"""
def __init__(self):
"""
Initialize the variables for the class
"""
self.wins = 0
self.losses = 0
self.ties = 0
self.options = {'rock': 0, 'paper': 1, 'scissors': 2}
def random_choice(self):
"""
Chooses a choice randomly from the keys in self.options.
:returns: String containing the choice of the computer.
"""
return random.choice(list(self.options.keys()))
def check_win(self, player, opponent):
"""
Check if the player wins or loses.
:param player: Numeric representation of player choice from self.options
:param opponent: Numeric representation of computer choice from self.options
:return: Nothing, but will print whether win or lose.
"""
result = (player - opponent) % 3
if result == 0:
self.ties += 1
print("The game is a tie! You are a most worthy opponent!")
elif result == 1:
self.wins += 1
print("You win! My honor demands a rematch!")
elif result == 2:
self.losses += 1
print("Haha, I am victorious! Dare you challenge me again?")
def print_score(self):
"""
Prints a string reflecting the current player score.
:return: Nothing, just prints current score.
"""
print(f"You have {self.wins} wins, {self.losses} losses, and "
f"{self.ties} ties.")
def run_game(self):
"""
Plays a round of Rock-Paper-Scissors with the computer.
:return: Nothing
"""
while True:
userchoice = input("Choices are 'rock', 'paper', or 'scissors'.\n"
"Which do you choose? ").lower()
if userchoice not in self.options.keys():
print("Invalid input, try again!")
else:
break
opponent_choice = self.random_choice()
print(f"You've picked {userchoice}, and I picked {opponent_choice}.")
self.check_win(self.options[userchoice], self.options[opponent_choice])
if __name__ == "__main__":
game = RockPaperScissors()
while True:
game.run_game()
game.print_score()
while True:
continue_prompt = input('\nDo you wish to play again? (y/n): ').lower()
if continue_prompt == 'n':
print("You are weak!")
exit()
elif continue_prompt == 'y':
break
else:
print("Invalid input!\n")
continue
You've picked rock, and I picked rock.
The game is a tie! You are a most worthy opponent!
You have 0 wins, 0 losses, and 1 ties.
You are weak!
You are weak!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
You are weak!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!
Invalid input!