HOMEWORK:
Math expressions: Write and calculate these expressions in Python.
e^5
Ceiling function of the square root of 127
Card exercise
Create a tuple to represent the four suits of cards (hearts, diamonds, spades, and clubs), and another tuple for 13 possible values (2 - 10, J, Q, K, A).
Iterate over all possible cards.
Using the random module, deal three random cards.
Sets
Take input for the elements of a set (space-separated integers). Create the set, and then create another set. Print the intersection/elements in common.
RESOURCES:
Class slides: https://docs.google.com/presentation/d/1PTxphkoJcpzyN2h4qDsyk-6SG7_OzQCOC8G2w0CFYP8/edit?usp=sharing
Battleship code: https://replit.com/join/hlutbjbnyh-shravyas
Class example code: https://replit.com/join/uvyjosgvrd-shravyas
Coding platform: replit.com
Post your answers as a comment! I will post the solution before next class.
You can always email us at shravyassathish@gmail.com (mentor) or kingericwu@gmail.com (TA) or message us on Discord if you have any questions about the homework or what we covered in class.
import math
import random
1:
print("e^5: " + str(math.pow(math.e, 5)))
print("Ceiling of the square root of 127: " + str(math.ceil(math.sqrt(127))))
2:
suit = ("hearts", "diamonds", "spades", "clubs")
value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "jack", "king", "queen", "ace")
cards = []
for i in range(len(value)):
for j in range(len(suit)):
element = str(value[i]) + " of " + str(suit[j])
cards.append(element)
print(cards)
a = random.choice(cards)
print(a)
cards.remove(a)
b = random.choice(cards)
print(b)
cards.remove(b)
c = random.choice(cards)
print(c)
cards.remove(c)
3:
set = set()
set2 = {"fillerWord"}
elements = input("Input some elements spaced by a comma and a space: ").split(", ")
elements2 = input("Again, input some elements spaced by a comma and a space: ").split(", ")
for i in elements:
set.add(i)
for i in elements2:
set2.add(i)
set2.remove("fillerWord")
print(set2.intersection(set))