# Ava Smith # smi01868 # CSCI 1133H (001) # Assignment 2 #================= # Purpose: A Card game between the user and the computer where the highest card wins # Input Parameters: none # Return Values: returns none #================= def play_cards(): import random print("*****Game Start!*****") # Settimg values player_cards = int(random.randrange(1, 10)), int(random.randrange(1, 10)), int(random.randrange(1, 10)) computer_cards = int(random.randrange(1, 10)), int(random.randrange(1, 10)), int(random.randrange(1, 10)) player_score = 0 computer_score = 0 print("Your Cards: ", player_cards, "\n") # Round One print("*****Round one*****") index_num1 = -1 #Card Selection while index_num1 == -1: index_num1 = int(input("Enter player card index(1, 2, 3): ")) if index_num1 > 3 or index_num1 < 1: print("Invalid Index Num, must be 1, 2, or 3\n") index_num1 = -1 print("\n") print("You played:", player_cards[index_num1-1]) print("Computer Played:", computer_cards[0]) # Scoring if(player_cards[index_num1-1] > computer_cards[0]): print("You win! :)") player_score +=1 elif(player_cards[index_num1-1] < computer_cards[0]): print("You lose :(") computer_score += 1 elif(player_cards[index_num1-1] == computer_cards[0]): print("You tie :/, no points added") print("\n") print("--Round One Score--\nYour Score:", player_score, "Computer Score:", computer_score) print("\n") # Round Two print("*****Round Two*****") index_num2 = -1 #Card Selection while index_num2 == -1: index_num2 = int(input("Enter player card index(1, 2, 3): ")) if (index_num2 > 3) or (index_num2 < 1): print("Invalid Index Num, must be 1, 2, or 3\n") index_num2 = -1 elif index_num2 == index_num1: print("Invalid Index Num, cannot pick the same card twice\n") index_num2 = -1 print("\n") print("You played:", player_cards[index_num2-1]) print("Computer Played:", computer_cards[1]) # Scoring if(player_cards[index_num2-1] > computer_cards[1]): print("You win! :)") player_score +=1 elif(player_cards[index_num2-1] < computer_cards[1]): print("You lose :(") computer_score += 1 elif(player_cards[index_num2-1] == computer_cards[1]): print("You tie :/, no points added") print("\n") print("--Round Two Score--\nYour Score:", player_score, "Computer Score:", computer_score) print("\n") # Round Three print("*****Round Three*****") index_num3 = -1 #Card Selection while index_num3 == -1: index_num3 = int(input("Enter player card index(1, 2, 3): ")) if index_num3 > 3 or index_num3 < 1: print("Invalid Index Num, must pick 1, 2, or 3\n") index_num1 = -1 elif index_num3 == index_num1 or index_num3 == index_num2: print("Invalid Index Num, cannot pick the same card twice\n") index = -1 print("\n") print("You played:", player_cards[index_num3-1]) print("Computer Played:", computer_cards[2]) # Scoring if(player_cards[index_num3-1] > computer_cards[2]): print("You win! :)") player_score +=1 elif(player_cards[index_num3-1] < computer_cards[2]): print("You lose :(") computer_score += 1 elif(player_cards[index_num3-1] == computer_cards[2]): print("You tie :/, no points added") print("\n") print("--Round Three Score--\nYour Score:", player_score, "Computer Score:", computer_score) print("\n") # Game over print("*****Game Over*****") print("--Final Score--\nYour Score:", player_score, "Computer Score:", computer_score) if(player_score > computer_score): print("You win!!!") elif(player_score < computer_score): print("Computer wins!!!") else: print("You tied!")