Ive spent that last couple of days (inbetween my exams) playing around with python and learning about what sort of stuff it could do. Turns out it has the ability to write to a .wav file. so what did i do? wrote out a song. First on the guess what it is wins!
Please note that this is written in Python 3.0
Code
A blog where I talk about me and the interblag and news. Oh and all my crazy ideas.
Showing posts with label help. Show all posts
Showing posts with label help. Show all posts
Saturday, April 30, 2011
Tuesday, April 26, 2011
Python is fun!
Hey everyone (who's left that is) Sorry for the long long long delay in posting. Lately(and by lately i mean the past 2 hours) I've been teaching myself python. It started when i found Skulpt a nifty live, in-browser compiler for Python. Since then I've downloaded the IDE for windows and have been playing with it. So far I've written the beginnings of a Blackjack game but lost myself in how to equate the card names to values because i stored the cards in a map. Tomorrow i might start on a MTG program that would take your deck, shuffle it, draw a hand and keep track of mana etc. All command line based of course since Clarkson doesn't teach GUI applications (yet i hope). Anyways below is the code I have so far. Feel free to provide suggestions.
-----------------------------------
| Read no Further if you don't care |
-----------------------------------
-----------------------------------
| Read no Further if you don't care |
-----------------------------------
import random
deck = {1 : 'Ace of Hearts', 2:'Ace of Clubs', 3:'Ace of Spades', 4:'Ace of Diamonds',
5:'Two of Hearts', 6:'Two of Clubs', 7:'Two of Spades', 8:'Two of Diamonds',
9:'Three of Hearts', 10:'Three of Clubs',11:'Three of Spades',12:'Three of Diamonds',
13:'Four of Hearts', 14:'Four of Clubs', 15:'Four of Spades', 16:'Four of Diamonds',
17:'Five of Hearts', 18:'Five of Clubs', 19:'Five of Spades', 20:'Five of Diamonds',
21:'Six of Hearts', 22:'Six of Clubs', 23:'Six of Spades', 24:'Six of Diamonds',
25:'Seven of Hearts',26:'Seven of Clubs',27:'Seven of Spades',28:'Seven of Diamonds',
29:'Eight of Hearts',30:'Eight of Clubs',31:'Eight of Spades',32:'Eight of Diamonds',
33:'Nine of Hearts', 34:'Nine of Clubs', 35:'Nine of Spades', 36:'Nine of Diamonds',
37:'Ten of Hearts', 38:'Ten of Clubs', 39:'Ten of Spades', 40:'Ten of Diamonds',
41:'Jack of Hearts', 42:'Jack of Clubs', 43:'Jack of Spades', 44:'Jack of Diamonds',
45:'Queen of Hearts',46:'Queen of Clubs',47:'Queen of Spades',48:'Queen of Diamonds',
49:'King of Hearts', 50:'King of Clubs', 51:'King of Spades', 52:'King of Diamonds'}
hand = []
total = 0
def start():
m=random.randint(1,52)
hand.append(deck[m])
total = 0
def checkHand():
#To be implemented
def dealing(answer):
if answer == "HIT":
m=random.randint(1,52)
hand.append(deck[m])
checkHand()
print(hand, total)
response = input("Would you like to hit or stay? (Please note the Dealer sticks at 16) HIT/STAY \n")
dealing(response)
if answer == "STAY":
return
else:
print("Invalid Response...Quiting")
return
print("Hello and welcome to BlackJack 2011. Here are your first two cards: " )
start()
start()
checkHand()
print(hand,total)
response = input("Would you like to hit or stay? (Please note the Dealer sticks at 16) HIT/STAY \n")
dealing(response)
print(hand,total)
Subscribe to:
Posts (Atom)