[SOLVED] EECS1015:Lab4 Simple Python Program

25.99 $

Category:

Description

Rate this product
  • This lab only has one task, but it has requirements on various functions you need to define.
  1. GOALS/OUTCOMES FOR LAB
    • To practice functions definition and calling in Python
    • To continue practicing with string input and string processing
    • To continue practicing using loops and if statements – To write your own Python code
  1. LAB 4 – TASK/INSTRUCTIONS

Task 0: [This will be the same for all labs]: Start you code with comments that include this lab ID, your full name, email address, and student id as

This lab has only 1 task.  Please read carefully.  A video of this lab running is available here.

https://www.eecs.yorku.ca/~mbrown/EECS1015_Lab4.mp4  

 ee explanation of the task on next page.           

Main Task – Two Card Poker Game

In this lab you are to write a simple two card poker game as follows:

Each play of the game, the user will get two cards and the computer will get two cards.

Cards are an integer value between 2-14, but are printed out as 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A The winner of the game is based on the following rankings:

Pair (2 cards of the same value)

  • if both players have a pair, then the pair with the highest numerical value wins
  • if only one player has a pair, then the pair wins

Highest Cards

  • if neither player has a pair, then the player with the highest card wins.
  • if both players highest card is the same, then the winner goes to the player with the second highest card Tie: If both players have the exact same cards then no winner, it is a tie

Example:

[A] [A] beats [K] [K]  — when both players have a pair, the highest pair wins

[2] [2] beats [A] [K]  — if only one player has a pair, the pair wins

[A] [K] beats [A] [Q] – if neither has a pair, the highest card wins.  If both players have the same highest card, then the                                         2nd highest card wins (in this case, [K] (13) beats [Q] (12) ) [A] [2] beats [K] [Q] – Otherwise, the highest card wins.

If both plays have the same card, then it is a tie (e.g., [J] [8] and [J] [8] is a tie)

Your requirements – read carefully, there are functions you must define to get full marks:

  • Write a function named drawcards() [no parameters] that generates two random cards represented as integers with values [2 to 14] inclusive. Your function should return the two cards such that the first card is greater than or equal to the second card.

For example, if random numbers are 2 and 13, then your function should return in the order 13 and 2.

Please see notes on how to return two values with a function.

  • Write a function named card2str() [one parameter] that will convert a card integer value to a string and return the string result. Use the following conversion:

Cards with values between 2-10 should be converted their string representation “2” – “10”.

Card value 11 is “J”, value 12 is “Q”, value 13 is “K” and value 14 is “A”.

For example, card2str(2) will return “2”.  card2str(12) will return “Q”

  • Write a function named printhand() [three parameters] that will print out the two cards as follows (depending on the player and their cards). [A] [2] Your Cards

[3] [3] Computer’s Cards

  • Write a function named printoutcome() [four parameters] that will print out if you win, lose, or tie. This function should take four arguments (your 2 cards and the computer’s 2 cards).  In my opinion, this is the most difficult function for lab 4.  Take care to get it work properly.  This functoin needs to compute the correct answer based on the ranking criteria above.
  • You program should play one round of the game an then ask the user if you’d like to play again (Y/N). If the user doesn’t type in “N” or “n”, keep playing the game.

Note that you can have more functions that mentioned above, but we will be expecting to see: drawCards, card2str, printhand, printoutput

See next page for example game play.

Example of game play:

** EECS1015 — AMAZING TWO CARD POKER GAME **

Pair wins

[K] [K] YOUR CARDS

[K] [9] COMPUTER’S CARDS

YOU WIN

Want to play again? (Y/N) y

High card wins

[10] [9] YOUR CARDS

[9] [7] COMPUTER’S CARDS

YOU WIN

Want to play again? (Y/N) y

High card wins

[K] [9] YOUR CARDS

[Q] [5] COMPUTER’S CARDS

YOU WIN

Want to play again? (Y/N) y

[7] [7] YOUR CARDS             Highest pair wins

[A] [A] COMPUTER’S CARDS  YOU LOSE!

Want to play again? (Y/N) y

[7] [4] YOUR CARDS             High card wins

[10] [4] COMPUTER’S CARDS

YOU LOSE

Want to play again? (Y/N) y

[J] [9] YOUR CARDS             High card wins

[6] [5] COMPUTER’S CARDS

YOU WIN

Want to play again? (Y/N) y

[A] [2] YOUR CARDS              High card wins

[Q] [8] COMPUTER’S CARDS

YOU WIN

Want to play again? (Y/N) y

[J] [10] YOUR CARDS            High card wins

[Q] [2] COMPUTER’S CARDS

YOU LOSE

Want to play again? (Y/N) y

[7] [6] YOUR CARDS             High card wins

[9] [7] COMPUTER’S CARDS

YOU LOSE

Want to play again? (Y/N) y

[A] [9] YOUR CARDS              2nd highest card wins

[A] [2] COMPUTER’S CARDS

YOU WIN

Want to play again? (Y/N) y

[J] [8] YOUR CARDS              High card wins

[Q] [2] COMPUTER’S CARDS

YOU LOSE

Want to play again? (Y/N) N     STOP PLAYING                           

** Thank you for playing! **

WATCH VIDEO OF LAB PROGRAM: https://www.eecs.yorku.ca/~mbrown/EECS1015_Lab4.mp4  

GRADING SCHEME

This lab is more challenging than lab 3 and 4.   However, the notes and trinkets examples are all sufficient to help you do this lab.  To get full marks you need to make sure you follow the instructions correctly.   The following will be our grading scheme for the Lab components specified in Section 2 of this document.

Task 0: (0 points, but deduction if you skip this part)

  • File name must be “py” (all lowercase, no spaces)
  • The Python comments at the beginning of your program must include your name, email, and York student id (this is important for grading)
  • If your file name is incorrect, your or do not put in the required information we will deduct -5 points (Why are we so harsh? Because if you don’t put in your name and student id it can be very difficult for the TAs to determine whose submission this is.)

Task 1:

  • You need to ensure that you implement all the functions required.
  • Please watch the accompanying video to see the program running.\

See pages below on how to submit your lab code. MAKE SURE TO SELECT Lab4 with websubmit