python:py_lists:py_code
| • | P Y T H O N • C O D E • E X A M P L E S | • |
| Title | |||
|---|---|---|---|
| Search | b | c | d |
| Sorting | b | c | d |
| Strings | b | c | d |
| Math | b | c | d |
| Array | b | c | d |
| Linked List | b | c | d |
| Stacks | b | c | d |
| Queues | b | c | d |
| Hash Tables | b | c | d |
| Binary Tree | b | c | d |
| Binary Heap | b | c | d |
| Graphs | b | c | d |
| yyy | b | c | d |
| yyy | b | c | d |
| a | b | c | d |
| a | b | c | d |
| a | b | c | d |
| Build a Deck of 52 Cards |
|---|
import random
suits = ["Clubs", "Diamonds", "Hearts", "Spades"]
faces = ["Jack", "Queen", "King", "Ace"]
numbered = [2, 3, 4, 5, 6, 7, 8, 9, 10]
deck = set()
for suit in suits:
for card in faces + numbered:
deck.add((card, "of", suit))
def draw ():
card = random.choice(list(deck))
deck.remove(card)
return card
card = ("Ace", "of", "Hearts")
card in deck
print(draw())
if card in deck:
print("that card is available")
else:
print("that card already taken")
ml = "Wolf,Knoll,Orc,Troll,Dragon"
monster1, monster2, monster3, monster4, monster5 = ml.split(",")
|
| Swim Code |
|---|
import statistics
FN = "Darius-13-100m-Fly.txt"
FOLDER = "swimdata/"
with open(FOLDER + FN) as file:
lines = file.readlines()
times = lines[0].strip().split(",")
converts =[]
for t in times:
minutes, rest = t.split(":")
seconds, hundredths = rest.split(".")
converts.append((int(minutes) * 60 * 100) + (int(seconds) * 100) + int(hundredths))
average = statistics.mean(converts)
average / 100
round(average / 100, 2)
min_secs, hundredths = str(round(average /100, 2)).split(".")
min_secs = int(min_secs)
minutes = min_secs // 60
minutes
seconds = min_secs - minutes*60
seconds
average = str(minutes) + ":" + str(seconds) + "." + hundredths
|
python/py_lists/py_code.txt · Last modified: by adminguide
