Question

In: Computer Science

Challenges Using Python 3. Write a program that displays the name of a card randomly chosen...

Challenges Using Python 3. Write a program that displays the name of a card randomly chosen from a complete deck of 52 playing cards. Each card consists of a rank (Ace. 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) and a suit (Clubs, Diamonds, Hearts. Spades).

Solutions

Expert Solution

#Here we will use libraries such as random & itertools

import itertools    #Import itertools library to iterate over lists
import random       #Import random library for randomize operations
# Define the list of ranks to be allocated
rank = ['Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King']
# Define a list of suit to be allocated
suit = ['Clubs','Diamonds','Hearts','Spades']
# Prepare a complete deck comprising of 52 pairs
complete_deck = list(itertools.product(rank,suit))
# Choosing a random card number
num = random.randint(1,52)
# print the card
print('Your card is %s of %s' % (str(complete_deck[num][0]), str(complete_deck[num][1])))


Related Solutions

Using python Write a program that displays all of states in the U.S. and display each...
Using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
PYTHON program that: Asks for a name, and then displays "Welcome student" plus your name on...
PYTHON program that: Asks for a name, and then displays "Welcome student" plus your name on the screen. (concatenate your name after the string) and prompts the user for 2 numbers, then calculates and displays the sum, product and average.
Write a Python program that has the user enter their name.   Using the user's name calculate...
Write a Python program that has the user enter their name.   Using the user's name calculate the following: 1. How many letters are in the user's name? 2. Print the user's name in REVERSE both in capital letters and lowercase letters 3. Print the ASCII value for each letter of the user's name. 4. Print the SUM of all of the letters of the user's name (add each letter from #3)
IN PYTHON: Write a program that displays the lines from the total.txt file in the following...
IN PYTHON: Write a program that displays the lines from the total.txt file in the following output. Use a try catch phrase to check for errors. Use only one function for this portion [main()]. Remember to use Python. Sample output below: 19 16, 29 3, 30 4, 34
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
Instructions from your teacher: Write a Python program that does the following: Displays a welcome message...
Instructions from your teacher: Write a Python program that does the following: Displays a welcome message Prompts a user to enter a number (an integer), and then converts that value from inches to feet. If the user entered a negative number, display an error message telling the user that it was not a "positive " number and prompt the user to enter a number again. Displays the converted value, then " feet" Continue converting the user's valid values until the...
Python Programming Write a simple implementation of a card deck to deal cards out randomly. Your...
Python Programming Write a simple implementation of a card deck to deal cards out randomly. Your Deck class will contain a list of card objects. Initially, the deck will contain one instance of each of the 52 possible cards. Your deck should implement a deal() method that chooses a random location from the list and "pops" that card. You should also implement a cardsLeft method that tells how many cards are left in the deck. Please type code and include...
for Python 3 Write a python program that Creates a list that has these values in...
for Python 3 Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below. Define a guessNext function that selects a random element from the list and returns it to the call of the function....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT