Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED HELP USING PYTHON Requirements: follow the given roles to program the blackjack game. use the given module (separate python file and images) to

I NEED HELP USING PYTHON

Requirements:

  • follow the given roles to program the blackjack game.
  • use the given module (separate python file and images) to display physical cards
  • use as many functions as possible, I gave you some framework for your reference.
  • use skills you learned from this class(loop, if, list, random)
  • submit your notebook online.

This is a blackjack program. In the beginning, you have $1000 to play the game.

For each game, you need to bet some money, say x dollars.

- if you win, your total money = 1000 + x

- if you lose, your total money = 1000 -x

- if you tie with the program, your money has no change.

You can play this game as many rounds as you have money. You can also choose to quit after each round.

Game Roles:

(1) At first, you, the player, need to bet some money. Then you will get two random cards.

(2) The card values:

- Ace: you can choice either 1 or 11 points

- Jack: value = 10 points

- Queen: value = 10 points

- King: value = 10 points

- Others: value = card face number

(3) Dealer also has two cards. If the deal draws an Ace, 50:50 for 1 point or 11 points

- the dealer's card and total points are unknown to the player

(4) Display player's two cards and the total points. After you see your first two cards, you have the chance to draw additional cards (hit), limited to 2 additional cards at most. You also can pass (stand).

(5) If you draw a additional card, dealer will do the same

(6) If points > 21, points = 0, bust apply to both you and dealer

(7) Then dealer total points will compare with yours

- if yours is higher than the dealer's, you win

- if equal, tie

- if yours is lower, you lose

(8) Now you finish one game.

The program will ask if the player player again or not. Player can play until you quit or no more money left

  • Ignore possible duplicated cards (shuffle can help)
  • Ignore the Blackjack(If you start (Ace & 10) )
  • 'Hit': ask for another card.
  • 'Stand':hold your total and end a game.
  • 'Bust': over 21 points

image text in transcribed

image text in transcribed

image text in transcribed image text in transcribed

#!/usr/bin/env python # coding: utf-8 # In[1]: # given function: display cards import ipywidgets as widgets from IPython display import Image, HTML, display input: card_names (a list, all names in low cases). example: card_names ["10_of_hearts", "jack_of_clubs", "ace_of_diamonds"] - images: saved in your current directory/deck/ - display: side by side - return: none # open images files def card_display(card_names): length = len(card_names) if length == 0: print(" There is no card!") else: # create a list for display card_list = [] # read in cards one by one and store in card_list for i in range (length): # path + card + .png path_name = './deck/'+ card_names[i] + '.png' img = open(path_name, 'rb').read() img_resize = widgets. Image (value= img, format='png', width=80, height=60) card_list.append(img_resize) # Side by side widges in HBox widgets sidebyside = widgets.HBox(card_list) # display display (sidebyside) TEST # # for one card # card_display(["queen_of_clubs"]) # # for two card # card_display (I "jack_of_clubs", "ace_of_diamonds"]) # for three card # card_display([ "10_of_hearts", "jack_of_clubs", "ace_of_diamonds"]) In [ ]: Before you start, please run the this cell first. Code is used for displaying cards, pause 3 seconds, and clear the scren # card_display.py: given module for card display # to use it: import card_display and rename it as cd from IPython.display import clear_output import card_display as cd import time #------- TEST Card Display- # # for one card: use list cd.card_display(["jack_of_clubs"]) # display time. sleep (3) # pasue 2 seconds clear_output (wait=True) # clear the screen # more cards cd.card_display(["queen_of_diamonds", "ace_of_spades", "5_of_clubs", "10_of_diamonds"]) time. sleep (3) clear_output(wait=True) In [ ]: given function: draw a card for you. import random def draw_card(): This function will draw a random card from 52 poker cards for you input: none return: card_num: int type, between 1 to 13 card_name: String type for example: if card_num is 1, use "ace", for 11, use "jack"; 12 "queen"; and 13 "king"; for others, card no change. "ace_of_clubs" means ace of clubs; suit_num= random.randint(1,4) if suit_num == 1: suit = "spades" elif suit_num == 2: suit = "clubs" elif suit_num == 3: suit = "hearts" else: suit "diamonds" card_num random.randint(1,13 if(card_num == 1): card_name ="ace" elif (card_num== 11): card_name ="jack" elif (card_num== 12): card_name ="queen" elif (card_num== 13): card_name ="king" else: card_name=str (card_num) return card_num, card_name + "_of_" + suit -test card_num, card_name, = draw_card) print("\t Card_num:", card_num, "\tCard_name:", card_name, ) cd.card_display([card_name])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions