Question

I have to write a program where the program prints a deck of cards. instead of having your regular suits and numbers the program will use a value for a number, id will be either rock, paper, or scissors, and the coin will be heads or tails. print example: 2 of rock heads. If the user is enters 1 the program will print out 30 of the print example and arrange them by there values. if the user enters 2 it will print out 30 of the print statements and arrange them by there id. I need to use a selection sort. how would I code this.

assn15-taski py ฝั่ assn 1 5-task2.py ї.assn15-task3.py 6deck.ру х card py i 6 gubbins til py x d plan-assn15-task3 ; Χ x rom

6 assn 15-taski py x 6 assn15-task2.py x 6 assn15-task3.py B deck.ру 6card.py x 6 gubbinsutil.py x d plan-assn15-task3 x impo

ilassn15-taskipy, assn15-task2.py 眼assn15-task3.py x deck.py x & card.py一眼gubbinsutil.py × d plan-assn15-task3 x ㄨ class Card

0 0
Add a comment Improve this question Transcribed image text
Answer #1

from deck import Deck

def main():

               deck = Deck()

               while True:

                              hand = []

                             

                             

                              print("")

                              print("New Hand")

                              print("")

                              print("1) Sort by value")

                              print("2) Sort by id")

                              print("3) Find card")

                              print("4) New Hand")

                              print("5) Quit")

                              menu = eval(input("Make a selection : "))

                             

                              if menu == 1: # sort by card value

                                             for i in range(30):

                                                            hand.append(deck.draw())

                                            

                                             print(hand)

                                             for i in range(len(hand)-1):

                                                            min = i

                                                            for j in range(i,len(hand)):

                                                                           if hand[j].getCardValue() < hand[min].getCardValue():

                                                                                          min = j

                                                            if min != i:

                                                                           hand[i],hand[min] = hand[min],hand[i]

                                             print('Sorted by Value: ')               

                                             print(hand)                                       

                              elif menu == 2: # sort by card id

                                             for i in range(30):

                                                            hand.append(deck.draw())

                                            

                                             print(hand)

                                             for i in range(len(hand)-1):

                                                            min = i

                                                            for j in range(i,len(hand)):

                                                                           if hand[j].getHand() < hand[min].getHand():

                                                                                          min = j

                                                            if min != i:

                                                                           hand[i],hand[min] = hand[min],hand[i]

                                                                          

                                             print('Sorted by Id: ')

                                             print(hand)         

                                                                          

                              elif menu == 3:

                                             search = eval(input('Enter a value to search for : '))

                                             if search <= 52:

                                                            print("1) Rock")

                                                            print("2) Paper")

                                                            print("3) Scissors")

                                                            hand = eval(input("Enter a hand : "))

                                                            if hand <= 4:

                                                                           print("1) Heads")

                                                                           print("2) Tails")

                                                                           coin = eval(input("Choose a coin : "))

                                                                          

                              elif menu == 4:

                                             main()

                                            

                              elif menu == 5:

                                             print("Thanks for playing")

                                             break

main()                                 

#end of program

Code Screenshot:

1 2 3 from deck import Deck def main() : deck Deck () while True: hand [1 print() print(New Hand) print () print(1) So

elif menu-_: 2: # sort by card 1d 34 35 36 37 38 39 40 41 4 2 43 for i in range (30): hand.append (deck.draw)) print (hand) f

Output:

D:python myprograms>python deck of_cards.py New Hand 1) Sort by value 2) Sort by id ) Find card 4) New Hand 5) Quit Make a se

Add a comment
Know the answer?
Add Answer to:
I have to write a program where the program prints a deck of cards. instead of having your regula...
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
  • I am having trouble with my Python code in this dictionary and pickle program. Here is...

    I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...

  • For my computer class I have to create a program that deals with making and searching...

    For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...

  • I am currently facing a problem with my python program which i have pasted below where...

    I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...

  • I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i...

    I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • I want to have a code that can pick whichever two planets in the solar system and find the distance of them no matter where in their orbit they are, but I keep getting errors. Can someone please help...

    I want to have a code that can pick whichever two planets in the solar system and find the distance of them no matter where in their orbit they are, but I keep getting errors. Can someone please help me fix it? f rom scipy import exp, pi, absolute, linspace import matplotlib. Ryplot as plt planet-I input ('Which planet do you want to pick for planet 1?") planet_2 input ('which planet do you want to pick for planet 27') distance...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

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
ADVERTISEMENT