Question

Python program please help. (cant use break statements and needs to be in function) 1) Write...

Python program please help. (cant use break statements and needs to be in function)

1) Write a function 'drawCard' that randomly selects a card and returns its value and suit sign. Call this function from main function and print the card information that was drawn inside main function. Assume the two lists as follows:
Hint: Use index to access the item valueList = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']
signList = ['heart','club','diamond', 'spade']

2) Write a function 'HalleyCometSightingYears' that takes number of sightings of the comet as a parameter and prints out the years in which it was observed since 1530. Generally it is observed every 76 years (+- by 1 or 2 years but we will ignore that for now). So the next sighting was in year 1606, then in 1682, and so on... Call this function from within main function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
This is a very big question. 
I have solved all of them. 
Please give me an upvote dear, Much Appreciated.!!
SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.


import random

def drawCard(valueList, signList):
    # get a sign
    sign_index = random.randint(0, 3)
    card = signList[sign_index]
    # draw a value
    value_index = random.randint(0, 13)
    card += ' '+str(valueList[value_index])
    # return the card
    return card


# TEST in main
if __name__ == '__main__':
    valueList = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']
    signList = ['heart', 'club', 'diamond', 'spade']

    print('Draw: ', drawCard(valueList, signList))
    print('Draw: ', drawCard(valueList, signList))
    print('Draw: ', drawCard(valueList, signList))
    print('Draw: ', drawCard(valueList, signList))

================

2.

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

def HalleyCometSightingYears(numSightings):
    print("The ", numSightings, " sightings are: ")
    # start with 1530
    num = 1530
    for x in range(numSightings):
        print(num)
        # add 76 to number
        num += 76


if __name__ == '__main__':
    # TEST
    HalleyCometSightingYears(10)

============

Add a comment
Know the answer?
Add Answer to:
Python program please help. (cant use break statements and needs to be in function) 1) Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. This is a fun "mind-reading" trick you can do with your students. Have each of your students think of a card. Each card has a numerical value: An Ace is worth 1, deuce 2,..., Jack 11,...

    1. This is a fun "mind-reading" trick you can do with your students. Have each of your students think of a card. Each card has a numerical value: An Ace is worth 1, deuce 2,..., Jack 11, Queen 12, King 13; and each suit has a value: a Club is worth 5, Diamond 6, Spade 7, and Heart 8. Let each student take the numerical value of their card (for example a Jack is 11) and add the next consecutive...

  • This activity needs to be completed in the Python language. This program will simulate part of...

    This activity needs to be completed in the Python language. This program will simulate part of the game of Poker. This is a common gambling game comparing five-card hands against each other with the value of a hand related to its probability of occurring. This program will simply be evaluating and comparing hands, and will not worry about the details of dealing and betting. Here follow the interesting combinations of cards, organized from most common to least common: Pair --...

  • C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playi...

    C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playing cards contains 52 cards. There are four suits (heart, diamond club +, spade+) and thirteen ranks (ace, 2 thru 10,jack, queen, king) per suit. Rank Numeric Value 10 10 10 10 gueen 10 Write a program that does the following: I. Simulates a randomized shuffling of a 52 card deck 2. Determines how many combinations of 21 exist in the deck by following...

  • Hi! I need help with a C++ program In this assignment, you will create some routines...

    Hi! I need help with a C++ program In this assignment, you will create some routines that will later be used in a "Black Jack" program. Your output on this first part will look something like: card's name is QC with a black jack value of 10 Unshuffled Deck AC/1 2C/2 3C/3 4C/4 5C/5 6C/6 7C/7 8C/8 9C/9 TC/10 JC/10 QC/10 KC/10 AD/1 2D/2 3D/3 4D/4 5D/5 6D/6 7D/7 8D/8 9D/9 TD/10 JD/10 QD/10 KD/10 AH/1 2H/2 3H/3 4H/4 5H/5...

  • With the code given write python code that prints the probablity of getting a straight in...

    With the code given write python code that prints the probablity of getting a straight in poker when you run 10**5 trails. HELPER CODE: # We will represent cards as a string, e.g., 'AC' will be Ace of Clubs # Denominations: 2, ..., 10, 'J' = Jack, 'Q' = Queen, 'K' = King, 'A' = Ace Denominations = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] # Suits 'S' = Spades, 'H' = Hearts, 'D' = Diamonds, 'C' = Clubs Suits = ['C', 'H', 'S', 'D'] #...

  • Can anyone please answer these? It's python coding question focusing on random practice!! 1. Write a...

    Can anyone please answer these? It's python coding question focusing on random practice!! 1. Write a function biasedCoinFlip(p) to return a biased coin flip that returns ''heads'' with probability p and tails otherwise. For example, when p=0.5, this function will behave like the last. On the other hand, p=0.25 will mean that there is only one chance in four of getting the result of "heads". 2. Write a function randomCard() to randomly return a card in a standard deck(suits: diamonds,...

  • 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card...

    7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card...

    (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...

  • C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data...

    C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT