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:
Slides: https://docs.google.com/presentation/d/1hi_-88CqHDAJwl9RUiJnrb5QTC3sjLGAQT2klFYm7iY/edit?usp=sharing
Class code: https://replit.com/join/ctozgytivw-shravyas
Contact Info:
shravyassathish@gmail.com (mentor)
kingericwu@gmail.com (TA)
felixguo41@gmail.com (TA)
1)
import math
print(math.pow(math.e,5))
print(math.ceil(math.sqrt(127)))
2)
from random import randint
tuplen = ("Hearts", "Daimonds", "Spades", "Clubs")
tuple = (2,3,4,5,6,7,8,9,10,"J","Q","K","A")
for i in tuplen:
for j in tuple:
print(str(j)+ " of " +i)
3)
setex = input("Please put some numbers separated by space: ").split()
setex = set(setex)
another = input("Please put some numbers separated by space: ").split()
another = set(another)
print(setex.intersection(another))
Solutions
1.
import math
print(math.pow(math.e,5))
print(math.ceil(math.sqrt(127)))
2.
from random import randint
suits=("D", "C", "H", "S")
cards=("A","2","3","4","5","6","7","8","9","10","J","Q","K")
for i in suits:
for z in cards:
str=[i,z]
print("".join(str))
print(suits[randint(0,len(suits)-1)],cards[randint(0,len(cards)-1)])
print(suits[randint(0,len(suits)-1)],cards[randint(0,len(cards)-1)])
print(suits[randint(0,len(suits)-1)],cards[randint(0,len(cards)-1)])
3.
seta=set()
for i in range(5):
seta.add(int(input()))
setb = set()
for i in range(5):
setb.add(int(input()))
for i in seta:
for z in setb:
if i == z:
print("both sets have",i)
import math
print(math.pow(math.e,5))
print(math.ceil(math.sqrt(127)))
Hearts = str("H")
Diamonds = str("D")
Spades = str("S")
Clubs = str("C")
Queen= str("Q")
King= str("K")
Ace= str("A")
Jack=str("J")
import random
shapetuple = (Hearts,Diamonds,Spades,Clubs)
facetuple=(2,3,4,5,6,7,8,9,10,Jack,Queen,King,Ace)
for i in shapetuple:
for j in facetuple:
print(i,j)
print("Random Cards Generated")
for i in range(0, 3):
randomShapeIndex = random.randint (0, 3)
shapeRandomPrint = shapetuple[randomShapeIndex]
randomFaceIndex = random.randint(0,12)
faceRandomPrint = facetuple[randomFaceIndex]
print(shapeRandomPrint, faceRandomPrint)
#
import math
print(math.pow(math.e,5))
print(math.ceil(math.sqrt(127)))
Hearts = str("H")
Diamonds = str("D")
Spades = str("S")
Clubs = str("C")
tuple = (Hearts,Diamonds,Spades,Clubs)
for i in tuple:
print(i)
Qween=("Q")
King=("K")
Ace=("A")
tuples = (Qween,King,Ace)
for i in tuples:
print(i)