EECS 1015 LAB #4 – Functions solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

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
2. 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 follows:
# Lab 4
# Author: Michael S. Brown
# Email: msb99898@aol.com
# Student ID: 10233030
This lab has only 1 task. Please read carefully. A video of this lab running is available here.


See explanation of the task on next page.
Page 2/7
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
2
nd 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:
(1) 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.
(2) 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”
(3) 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
(4) 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.
(5) 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.
Page 3/7
Example of game play:
** EECS1015 — AMAZING TWO CARD POKER GAME **
[K] [K] YOUR CARDS
[K] [9] COMPUTER’S CARDS
YOU WIN
Want to play again? (Y/N) y
[10] [9] YOUR CARDS
[9] [7] COMPUTER’S CARDS
YOU WIN
Want to play again? (Y/N) y
[K] [9] YOUR CARDS
[Q] [5] COMPUTER’S CARDS
YOU WIN
Want to play again? (Y/N) y
[7] [7] YOUR CARDS
[A] [A] COMPUTER’S CARDS
YOU LOSE!
Want to play again? (Y/N) y
[7] [4] YOUR CARDS
[10] [4] COMPUTER’S CARDS
YOU LOSE
Want to play again? (Y/N) y
[J] [9] YOUR CARDS
[6] [5] COMPUTER’S CARDS
YOU WIN
Want to play again? (Y/N) y
[A] [2] YOUR CARDS
[Q] [8] COMPUTER’S CARDS
YOU WIN
Want to play again? (Y/N) y
[J] [10] YOUR CARDS
[Q] [2] COMPUTER’S CARDS
YOU LOSE
Want to play again? (Y/N) y
[7] [6] YOUR CARDS
[9] [7] COMPUTER’S CARDS
YOU LOSE
Want to play again? (Y/N) y
[A] [9] YOUR CARDS
[A] [2] COMPUTER’S CARDS
YOU WIN
Want to play again? (Y/N) y
[J] [8] YOUR CARDS
[Q] [2] COMPUTER’S CARDS
YOU LOSE
Want to play again? (Y/N) N
** Thank you for playing! **
WATCH VIDEO OF LAB PROGRAM: https://www.eecs.yorku.ca/~mbrown/EECS1015_Lab4.mp4
Pair wins
High card wins
High card wins
Highest pair wins
High card wins
High card wins
High card wins
High card wins
High card wins
2
nd highest card wins
High card wins
STOP PLAYING
Page 4/7
3. GRADING SCHEME (Maximum number of points possible 10)
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 “lab4.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: (10 points each)
 You need to ensure that you implement all the functions required.
 Please watch the accompanying video to see the program running.
-No submission – 0 points
-Any submission 1 week after the due date 50% off the total marks
-Any submission 2 weeks after the due date will not be marked and treated as no submission.
See pages below on how to submit your lab code.
MAKE SURE TO SELECT Lab4 with websubmit
Page 5/7
4. SUBMISSIONS (EECS web-submit)
You will submit your lab using the EECS web submit.
Click on the follow URL: https://webapp.eecs.yorku.ca/submit
STEP 1 — If you don’t have an EECS account,
click here to use Passport York (everyone
has a passport York account).
If you do have an EECS account, enter here
and go to STEP 3.
STEP 1 — If you don’t have an EECS account,
click here to use Passport York (everyone
has a passport York account).
If you do have an EECS account, enter here
and go to STEP 3.
STEP 1 — If you don’t have an EECS account,
click here to use Passport York (everyone
has a passport York account).
If you do have an EECS account, enter here
and go to STEP 3.
STEP 2 – Enter your passport York
username/password.
Page 6/7
STEP 3 – Select the correct menu option
as follows. Term “F”, Course “1015”,
Assignment “Lab4”.
STEP 3 cont’ – Select your file. The location
in PyCharm may be complicated. I
recommend you save your PyCharm Python
file to your desktop and select from there.
Remember, name your file lab4.py.
STEP 3 cont’ – once you have entered
everything above, click “Submit Files”.
STEP 4 – Confirm that you have entered
everything in correctly. If you make a
mistake here and submit to the wrong
course, or wrong lab, we won’t be able to
tell and will mark your lab as not submitted.
Please double check before clicking OK.
Lab 4
lab4.py
Page 7/7
For more details on websubmit, see EECS department instructions:
https://wiki.eecs.yorku.ca/dept/tdb/services:submit:websubmit
STEP 5 – After you submit, your webpage
will refresh and show that you have
submitted the files and the time.
I recommend you logout.
You can resubmit the file if you make
changes. However, if the TA has already
graded your lab, they will not grade it again,
so I recommend you only upload once you
have it work.
lab4.py
lab4.py