Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An Introduction to Programming, Using Python. By David Schneider Chapter 6.2, Pr

ID: 3839394 • Letter: A

Question

An Introduction to Programming, Using Python. By David Schneider

Chapter 6.2, Problem 22

Locate First AceSuppose you shuffle an ordinary deck of 52 playing cards, and then turn up cards from the top until the first ace appears. On average, how many cards do you think must be turned up until the first ace appears? Estimate the average by writing a program that shuffles a deck of cards 100,000 times and finds the average of the number of cards that must be turned up to obtain an ace for each shuffle. See Fig. 6.9. Note: Your average will differ from the one in the figure, but should be close to 10.6. Using Python.

FIGURE 6.9 Possible outcome of Exercise 22.

Explanation / Answer

""" Author:ravi Date :15/5/17 File Name:main.py Description: """ import random class Card(object): """Represents a standard playing card. Attributes: suit: integer 0-3 rank: integer 1-13 """ suit_names = ["Clubs", "Diamonds", "Hearts", "Spades"] rank_names = [None, "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"] def __init__(self, suit=0, rank=2): self.suit = suit self.rank = rank def __str__(self): """Returns a human-readable string representation.""" return '%s of %s' % (Card.rank_names[self.rank], Card.suit_names[self.suit]) def __cmp__(self, other): """Compares this card to other, first by suit, then rank. Returns a positive number if this > other; negative if other > this; and 0 if they are equivalent. """ t1 = self.suit, self.rank t2 = other.suit, other.rank return (t1 > t2) - (t1
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote