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

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):...
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...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals method to compare two or more objects. Your should use your QC5 as a reference. …………………………...…….. …………………………...……. Instructions LAB5 Instructions Using QC5 as a model, create a Rectangle class and a CompareUsingequalsMethod class that uses an   equals Method to determine if two rectangles are equal if and only if their areas are equal. The Rectangle class should have two instance variables length and width....
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):
Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
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'; } } }
Review the General Programming Assignment instructions. In this chapter, the class dateType was designed to implement...
Review the General Programming Assignment instructions. In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear,...
Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT