top of page

Forum Comments

2/8 - Class 18 HW + Resources
In Introduction to Python
Eric Wu
Feb 16, 2022
Is this your work?
0
1/11 - Class 15 HW + Resources
In Introduction to Python
Eric Wu
Jan 26, 2022
Solutions: import random deck = ['CJ', 'CQ', 'CK', 'CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'DJ', 'DQ', 'DK', 'DA', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'HJ', 'HQ', 'HK', 'HA', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'SJ', 'SQ', 'SK', 'SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10'] hand = [] handnum = int(input("How many cards do you want in your hand?")) if handnum > 52: print("oops") print("The number you entered is bigger than 52") for x in range(handnum): z=random.randint(0,(len(deck)-1)) hand.append(deck[z]) deck.remove(deck[z]) print("Cards in hand:", hand) print("Cards in deck:", deck) while True: action = input("What would you like to do next? Draw card, shuffle deck, return card, r(repeat), exit\n") if action != "r" or "repeat": prevaction = action if action.lower() == "r" or "repeat": try: action = prevaction print("hi") except: print("oops") pass if action.lower() == "draw card": a = random.randint(0,(len(deck)-1)) hand.append(deck[a]) deck.remove(deck[a]) print(hand) elif action.lower() == "shuffle deck": random.shuffle(deck) print(deck) elif action.lower() == "exit": print("Thank you for playing") break elif action.lower() == "return card": print("Which card do you want to return from your hand? Card, random, all", hand) returncard = input() if returncard.lower() == "random": b = random.randint(0,(len(hand)-1)) deck.append(hand[b]) hand.remove(hand[b]) print("Card removed:", hand[b]) elif returncard.lower() == "all": deck.extend(hand) hand.clear() print(deck) else: try: deck.append(returncard.upper()) hand.remove(returncard.upper()) print(hand) except: print("Oops") else: print("Try again") pass
0
0
1/4 - Class 14 HW + Resources
In Introduction to Python
Eric Wu
Jan 11, 2022
Solution import random deck = ['CJ', 'CQ', 'CK', 'CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'DJ', 'DQ', 'DK', 'DA', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'HJ', 'HQ', 'HK', 'HA', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'SJ', 'SQ', 'SK', 'SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10'] hand = [] handnum = int(input("How many cards do you want in your hand?")) if handnum > 52: print("oops") print("The number you entered is bigger than 52") for x in range(handnum): z=random.randint(0,(len(deck)-1)) hand.append(deck[z]) deck.remove(deck[z]) print("Cards in hand:", hand) print("Cards in deck:", deck) while True: action = input("What would you like to do next? Draw card, shuffle deck, return card, r(repeat), exit\n") if action != "r" or "repeat": prevaction = action if action.lower() == "r" or "repeat": try: action = prevaction print("hi") except: print("oops") pass if action.lower() == "draw card": a = random.randint(0,(len(deck)-1)) hand.append(deck[a]) deck.remove(deck[a]) print(hand) elif action.lower() == "shuffle deck": random.shuffle(deck) print(deck) elif action.lower() == "exit": print("Thank you for playing") break elif action.lower() == "return card": print("Which card do you want to return from your hand? Card, random, all", hand) returncard = input() if returncard.lower() == "random": b = random.randint(0,(len(hand)-1)) deck.append(hand[b]) hand.remove(hand[b]) print("Card removed:", hand[b]) elif returncard.lower() == "all": deck.extend(hand) hand.clear() print(deck) else: try: deck.append(returncard.upper()) hand.remove(returncard.upper()) print(hand) except: print("Oops") else: print("Try again") pass
0
0
10/26 - Class 7 HW + Resources
In Introduction to Python

Eric Wu

Forum Moderator
More actions
bottom of page