Question

In: Computer Science

Instructions Use your solution from Programming Assignment 5 (or use your instructor's solution) to create a...

Instructions

Use your solution from Programming Assignment 5 (or use your instructor's solution) to create a modular Python application. Include a main function (and a top-level scope check),and at least one other non-trivial function (e.g., a function that deals the new card out of the deck). The main function should contain the loop which checks if the user wants to continue.

Include a shebang, and ID header, descriptive comments, and use constants where appropriate.

Sample Output (user input in red):

Welcome to the card dealer!
Here is your first card:
5 of hearts
Would you like another card? (y or n) y
King of hearts
Would you like another card? (y or n) y
Jack of clubs
Would you like another card? (y or n) y
King of spades
Would you like another card? (y or n) n
final hand value = 35
final hand: ['5 of hearts', 'King of hearts', 'Jack of clubs', 'King of spades']

Submission

Attach and submit your Python file to this assignment.

Solutions

Expert Solution

Python3 code:

import random
suits = ["clubs", "diamonds", "hearts", "spades"]
chars = ["ace", "king", "queen", "jack"]
total = random.randint(1,9)
print("Welcome to the card dealer!")
print("Here is your first card:")
temp = random.randint(0,3)
hand = []
hand.append(str(total) + " of " + suits[temp])
print(total, "of", suits[temp])
while(True):
print("Would you like to add another card? (y/n)")
inp = input().lower()
if(inp=="y"):
s = input().strip().split()
if(len(s)==3 and s[1]=="of" and (s[2].lower() in suits)):
#check for number from 1 to 9
if(s[0].isdigit() and int(s[0])>=1 and int(s[0]) <=9 ):
total+=int(s[0])
hand.append(str(s[0]) + " of "+ s[2])
#check for "ace", "king", "queen"
elif(s[0].lower() in chars):
total+=10
hand.append(s[0] + " of " + s[2])
else:
print("Wrong input!")
else:
print("Wrong input!")
elif(inp=="n"):
print("final hand value =",total)
print("final hand: ",hand)
break
else:
print("Wrong input. Please enter y or n")


Related Solutions

Using your solution or your instructor's solution from the Module 8 ungraded practice exercise, implement a...
Using your solution or your instructor's solution from the Module 8 ungraded practice exercise, implement a unit test for the Pair class by adding a main method. Create three small constituent classes (I created PeanutButter, Jelly, and Mustard classes) and insert various combinations of them into an array of Pair objects. Thoroughly test the equals(), hashCode(), and toString() methods from the Pair class with your main method. Note: override the toString() method in each of your constituent classes so they...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going to implement a simple C version of the UNIX cat program called lolcat. The cat program allows you to display the contents of one or more text files. The lolcat program will only display one file. The correct usage of your program should be to execute it on the command line with a single command line argument consisting of the name you want to...
The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
From question 19: findAndTruncate "...+2 EC (at the instructor's discretion) will go to the (correct) solution...
From question 19: findAndTruncate "...+2 EC (at the instructor's discretion) will go to the (correct) solution with the least number of statements ." Find two unneeded statements and one performance issue in the below code: findAndTruncate(char *trunc, const char placeholder) { for(int i = 0; *(trunc + i) != '\0'; i++)          { if(*(trunc + i) == placeholder)                    {    * (trunc + i) = '\0'; } } }
For this programming assignment, you will use your previous code that implemented a video game class...
For this programming assignment, you will use your previous code that implemented a video game class and objects with constructors. Add error checking to all your constructors, except the default constructor which does not require it. Make sure that the high score and number of times played is zero or greater (no negative values permitted). Also modify your set methods to do the same error checking. Finally add error checking to any input requested from the user. #include <iostream> #include...
You will create this assignment following the Assignment Detail instructions below. Review the tutorial titled How...
You will create this assignment following the Assignment Detail instructions below. Review the tutorial titled How to Submit the Intellipath Submission Assignment. Please submit your work to this week’s Intellipath Unit Submission lesson. Click the Upload button within the submission lesson to access the submission area. Click the Select File button to upload your document, and then click "OK" to finish. Assignment Details Throughout this class, you have been working with a product of your creation that dealt domestically. This...
Programming Assignment 5 Your work on the last project, the inventory ordering system, was so well...
Programming Assignment 5 Your work on the last project, the inventory ordering system, was so well received that your boss has asked you to write a new program for the firm. She mentions that she’s heard a lot about “Object Oriented Programming” and wants you to create a database of part’s suppliers that the company will use to source new inventory from. She mentions that there have been a lot of new entrants into the market and its important that...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT