February 23, 2015 23:34
Blogger
Python Extra Credit Assignment - EC0
February 21, 2015 04:02
Blogger
Blackjack & Yahtzee - Homework 5 Finished
The score for Yahtzee was really simple, but Blackjack was really challenging and I think that I couldn't have done the scoring of cards better since its hard coded at this time and the function has to switch through a bunch of different if statements.
This time around I used Pycharm, which is a really nice IDE for Python. Folding code and having the IDE correct you while you are coding makes it a lot easier than having to dig through a text editor to figure out what you did wrong!
We also had to draw up a design paper that would explain how you build the process of the game. It doesn't have to be perfect, but it was just to illustrate that you put some thought into how we build the game. Here is mine:
Anyways, here is what I made and thanks for reading:
#Assignment005_ChristianMunoz.py
#02/20/2014
import random
import math
import sys
import time
def sleeper(seconds):
"""This function suspends the thread for a given amount of seconds."""
time.sleep(seconds)
def make_deck():
"""Makes the list of Cards"""
card_symbols = '''AS AH AD AC
KS KH KD KC
QS QH QD QC
JS JH JD JC
10S 10H 10D 10C
9S 9H 9D 9C
8S 8H 8D 8C
7S 7H 7D 7C
6S 6H 6D 6C
5S 5H 5D 5C
4S 4H 4D 4C
3S 3H 3D 3C
2S 2H 2D 2C'''
card_symbols = card_symbols.split()
return card_symbols
def shuffle_deck(input_decks):
"""This function shuffles the deck of cards"""
random.shuffle(input_decks)
return input_decks
def roll_die():
"""Assigns a random number to the dice"""
return random.randint(1, 6)
def make_reroll_list(player_input):
"""Makes the list of which dice to roll"""
#tempString = tempString.split()
#return tempString
return [int(s) for s in player_input.split()]
def score_dice(dice_list, y_score):
"""Score the player's current set of dice."""
#temp_score = y_score
for i in range(1, 6):
count_i = dice_list.count(i)
#checks for Yahtzee
if count_i == 5:
y_score += 50
print("YAHTZEE!\nYour Score is:", y_score, "\n")
return y_score
#checks for Four of a Kind
elif count_i == 4:
y_score += 25
print("FOUR OF A KIND!\nYour score is:", y_score, "\n")
return y_score
#checks for Full House or Three of a Kind
elif count_i == 3:
for j in range(1, 6):
if dice_list.count(j) == 2:
y_score += 30
print("FULL HOUSE!\nYour score is:", y_score, "\n")
return y_score
else:
y_score += 20
print("THREE OF A KIND!\nYour score is:", y_score, "\n")
return y_score
#checks for Small Straight
small = [1, 2, 3, 4, 5]
for s in small:
if s not in dice_list:
break
else:
y_score += 35
print("SMALL STRAIGHT!\nYour score is:", y_score, "\n")
return y_score
#checks for Large Straight
large = [2, 3, 4, 5, 6]
for l in large:
if l not in dice_list:
break
else:
y_score += 40
print("LARGE STRAIGHT!\nYour score is:", y_score, "\n")
return y_score
#this just adds the faces together
y_score += sum(dice_list)
print("CHANCE!\nYour score is:", y_score, "\n")
return y_score
def query_reroll():
"""Ask the use which dice they want to reroll."""
reroll_list = input("Which die/dice would you like to reroll? Or just press enter to keep what you have.\n")
reroll_list = make_reroll_list(reroll_list)
return reroll_list
def reroll_dice(dice_list, reroll_list):
"""Reroll the given dice."""
for r in reroll_list:
dice_list[r - 1] = roll_die()
dice_list.sort()
def deal_card(deck,hand):
"""This function will check if the deck has enough cards and then deal one card.
In order to stop people from counting cards, this functions shuffles a new
deck if it goes below 26 cards"""
if int(len(deck)) > 26:
hand.append(deck.pop())
return deck, hand
else:
print("The deck is getting low, shuffling a new deck!\n.")
deck = make_deck()
deck = shuffle_deck(deck)
sleeper(.5)
print("..")
sleeper(.5)
print("...\n")
sleeper(.5)
print("The deck has been shuffled!\n")
hand.append(deck.pop())
return deck, hand
def get_values(hand):
"""Get the value of the cards"""
aces = 0
score = 0
aces += int(hand.count("AS"))
aces += int(hand.count("AH"))
aces += int(hand.count("AD"))
aces += int(hand.count("AC"))
for card in hand:
if card == "2S" or card == "2H" or card == "2D" or card == "2C":
score += 2
elif card == "3S" or card == "3H" or card == "3D" or card == "3C":
score += 3
elif card == "4S" or card == "4H" or card == "4D" or card == "4C":
score += 4
elif card == "5S" or card == "5H" or card == "5D" or card == "5C":
score += 5
elif card == "6S" or card == "6H" or card == "6D" or card == "6C":
score += 6
elif card == "7S" or card == "7H" or card == "7D" or card == "7C":
score += 7
elif card == "8S" or card == "8H" or card == "8D" or card == "8C":
score += 8
elif card == "9S" or card == "9H" or card == "9D" or card == "9C":
score += 9
elif card == "10S" or card == "10H" or card == "10D" or card == "10C":
score += 10
elif card == "JS" or card == "JH" or card == "JD" or card == "JC":
score += 10
elif card == "QS" or card == "QH" or card == "QD" or card == "QC":
score += 10
elif card == "KS" or card == "KH" or card == "KD" or card == "KC":
score += 10
if aces == 1 and score <= 10:
score += 11
elif aces > 0 and score > 10:
score += aces
return score
def blackjack(y_score):
"""This function will run the card game"""
player_hand = []
dealer_hand = []
deck = make_deck()
print("Shuffling the deck\n.")
sleeper(.5)
print("..")
sleeper(.5)
print("...\n")
sleeper(.5)
deck = shuffle_deck(deck)
print("The deck has been shuffled, we are ready to start!\n")
deck, player_hand = deal_card(deck,player_hand)
deck, dealer_hand = deal_card(deck,dealer_hand)
deck, player_hand = deal_card(deck,player_hand)
deck, dealer_hand = deal_card(deck,dealer_hand)
player_total = get_values(player_hand)
dealer_total = get_values(dealer_hand)
print("Your hand is: ", player_hand)
print("Dealer's top card is: ", dealer_hand[0])
if player_total == 21:
print("You got BLACKJACK!\n")
sleeper(.5)
print("The dealer has revealed his full hand: ", dealer_hand)
sleeper(.5)
if player_total == dealer_total:
print("\nThis is a DRAW!\n")
play_again(y_score)
else:
print("\nYou WIN!\n")
play_again(y_score)
else:
while player_total <= 21:
decision = input("Would you like to HIT or STAY? H/S\n").lower()
if decision == "h":
print("You have decided to HIT!\n")
deck, player_hand = deal_card(deck,player_hand)
player_total = get_values(player_hand)
print("Your hand is: ", player_hand)
if player_total > 21:
print("BUST!\nYou LOST\n")
sleeper(.5)
play_again(y_score)
elif decision == "s":
print("You have decided to STAY!\n")
sleeper(.5)
break
print("The dealer has revealed his full hand: ", dealer_hand)
sleeper(1.0)
if player_total == 21 and player_total == dealer_total:
print("This is a DRAW!\n")
play_again(y_score)
elif dealer_total == 21:
print("The dealer got BLACKJACK!\nYou LOST!\n")
play_again(y_score)
elif dealer_total > 16:
print("You got: ", player_total)
print("The dealer got: ", dealer_total)
if player_total > dealer_total:
print("\nYou WIN!\n")
play_again(y_score)
else:
print("\nYou LOST\n")
play_again(y_score)
else:
while dealer_total <= 16:
print("The dealer has to HIT again!\n")
sleeper(1.0)
deck, dealer_hand = deal_card(deck,dealer_hand)
dealer_total = get_values(dealer_hand)
print("The dealer's hand is: ", dealer_hand)
if dealer_total > 21:
print("The dealer got a BUST!\nYou WIN!")
play_again(y_score)
print("You got: ", player_total)
print("The dealer got: ", dealer_total)
if player_total > dealer_total:
print("\nYou WIN!\n")
play_again(y_score)
else:
print("\nYou LOST\n")
play_again(y_score)
def yahtzee(y_score):
"""This function will run the yahtzee game."""
print(" ")
dice_list = [roll_die() for i in range(0, 5)]
dice_list.sort()
print("First roll you got:", dice_list, "\n")
reroll_list = query_reroll()
reroll_dice(dice_list, reroll_list)
print("Second roll you got:", dice_list, "\n")
reroll_list = query_reroll()
reroll_dice(dice_list, reroll_list)
print("Third roll you got:", dice_list, "\n")
y_score = score_dice(dice_list, y_score)
play_again(y_score)
def play_again(y_score):
"""This function will run the next game if the player wants to start again"""
decision = input("Would you like to play again? Y/N\n").lower()
if decision == "yes" or decision == "y":
main(False, y_score)
elif decision == "no" or decision == "n":
print("See you later!")
else:
print("That is not a valid entry!\n")
play_again(y_score)
def main(first_time, y_score):
if first_time == True:
player_input = eval(input("Press 1 to play the Blackjack or 2 for Yahtzee:\n"))
#This makes sure that the number will always be an integer
player_input = math.floor(player_input)
#This checks to make sure the entry is a valid entry
if player_input < 1 or player_input > 2:
print("That is not a valid entry!\n")
main(True,y_score)
#If the entry was valid, then execute code
elif player_input == 1:
print("You have chosen Blackjack!\n")
blackjack(y_score)
else:
print("You have chosen Yahtzee!")
yahtzee(y_score)
else:
player_input = eval(input("Press 1 to play the Blackjack or 2 for Yahtzee:\n"))
#This makes sure that the number will always be an integer
player_input = math.floor(player_input)
#This checks to make sure the entry is a valid entry
if player_input < 1 or player_input > 2:
print("That is not a valid entry!\n")
main(False, y_score)
#If the entry was valid, then execute code
elif player_input == 1:
print("You have chosen Blackjack!\n")
blackjack(y_score)
else:
print("You have chosen Yahtzee!")
yahtzee(y_score)
if __name__ == "__main__":
main(True,0)
sleeper(1.0)
sys.exit()
February 18, 2015 22:46
Blogger
A Blackjack of all Trades
The assignment specifies that for the Yahtzee game we have to find a way to make the game memorize the player's total score for all the Yahtzee games he/she has played without using variable.
I know that I will have to go back and make a few changes, but for now this is what I have and thanks for reading:
#Assignment005_ChristianMunoz.py
#02/18/2014
import random
import math
import sys
import time
def sleeper(seconds):
"""This function suspends the thread for a given amount of seconds."""
time.sleep(seconds)
def makeListOfCards(stringOfCards):
"""Makes the list of Cards"""
listOfCards = stringOfCards.split()
return listOfCards
def shuffleDeck(inputDecks):
"""Shuffle code"""
shuffledDeck = []
for i in range(len(inputDecks)):
tempInt = random.randint(0,len(inputDecks) - 1)
shuffledDeck.append(inputDecks.pop(tempInt))
return(shuffledDeck)
def roll_die():
"""Assigns a random number to the dice"""
return random.randint(1, 6)
def make_reroll_list(player_input):
"""Makes the list of which dice to roll"""
#tempString = tempString.split()
#return tempString
return [int(s) for s in player_input.split()]
def score_dice(dice_list, y_score):
"""Score the player's current set of dice."""
temp_score = y_score
for i in range(1, 6):
count_i = dice_list.count(i)
#checks for Yahtzee
if count_i == 5:
temp_score += 50
print("YAHTZEE!\nYour Score is:", temp_score, "\n")
return temp_score
#checks for Four of a Kind
elif count_i == 4:
temp_score += 25
print("FOUR OF A KIND!\nYour score is:", temp_score, "\n")
return temp_score
#checks for Full House or Three of a Kind
elif count_i == 3:
for j in range(1, 6):
if dice_list.count(j) == 2:
temp_score += 30
print("FULL HOUSE!\nYour score is:", temp_score, "\n")
return temp_score
else:
temp_score += 20
print("THREE OF A KIND!\nYour score is:", temp_score, "\n")
return temp_score
#checks for Small Straight
small = [1, 2, 3, 4, 5]
for s in small:
if s not in dice_list:
break
else:
temp_score += 35
print("SMALL STRAIGHT!\nYour score is:", temp_score, "\n")
return temp_score
#checks for Large Straight
large = [2, 3, 4, 5, 6]
for l in large:
if l not in dice_list:
break
else:
temp_score += 40
print("LARGE STRAIGHT!\nYour score is:", temp_score, "\n")
return temp_score
#this just adds the faces together
temp_score += sum(dice_list)
print("CHANCE!\nYour score is:", temp_score, "\n")
return temp_score
def query_reroll():
"""Ask the use which dice they want to reroll."""
reroll_list = input("Which die/dice would you like to reroll? Or just press enter to keep what you have.\n")
reroll_list = make_reroll_list(reroll_list)
return reroll_list
def reroll_dice(dice_list, reroll_list):
"""Reroll the given dice."""
for r in reroll_list:
dice_list[r - 1] = roll_die()
dice_list.sort()
def blackjack():
"""This function will run the card game"""
decksToShuffle = eval(input("Enter how many decks you would like to shuffle at once (1-5): "))
print(" ")
#This makes sure that the number will always be an integer
decksToShuffle = math.floor(decksToShuffle)
#This checks to make sure the entry is a valid entry
if decksToShuffle <= 0 or decksToShuffle > 5:
print("That is not a valid entry!")
print(" ")
cardGame()
#If the entry was valid, then execute code
else:
CardSymbols = '''AS AH AD AC
KS KH KD KC
QS QH QD QC
JS JH JD JC
10S 10H 10D 10C
9S 9H 9D 9C
8S 8H 8D 8C
7S 7H 7D 7C
6S 6H 6D 6C
5S 5H 5D 5C
4S 4H 4D 4C
3S 3H 3D 3C
2S 2H 2D 2C'''
listOfCards = makeListOfCards(CardSymbols) * decksToShuffle
print("Shuffling the deck\n.")
sleeper(.5)
print("..")
sleeper(.5)
print("...")
sleeper(.5)
print(" ")
print(shuffleDeck(listOfCards))
print(" ")
play_again()
def yahtzee(y_score):
"""This function will run the yahtzee game."""
temp_score = y_score
print(" ")
dice_list = [roll_die() for i in range(0, 5)]
dice_list.sort()
print("First roll you got:", dice_list, "\n")
reroll_list = query_reroll()
reroll_dice(dice_list, reroll_list)
print("Second roll you got:", dice_list, "\n")
reroll_list = query_reroll()
reroll_dice(dice_list, reroll_list)
print("Third roll you got:", dice_list, "\n")
temp_score = score_dice(dice_list, temp_score)
play_again(temp_score)
def play_again(y_score):
"""This function will run the next game if the player wants to start again"""
temp_yscore = y_score
decision = input("Would you like to play again? Y/N\n").lower()
if decision == "yes" or decision == "y":
player_input = eval(input("Press 1 to play the Blackjack or 2 for Yahtzee:\n"))
#If the entry was valid, then execute code
if player_input == 1:
print("You have chosen Blackjack!\n")
blackjack()
else:
print("You have chosen Yahtzee!")
yahtzee(temp_yscore)
else:
print("See you later!")
def main(first_time):
y_score = 0
player_input = eval(input("Press 1 to play the Blackjack or 2 for Yahtzee:\n"))
#This makes sure that the number will always be an integer
player_input = math.floor(player_input)
#This checks to make sure the entry is a valid entry
if player_input < 1 or player_input > 2:
print("That is not a valid entry!\n")
main()
#If the entry was valid, then execute code
elif player_input == 1:
print("You have chosen Blackjack!\n")
blackjack()
else:
print("You have chosen Yahtzee!")
yahtzee(y_score)
if __name__ == "__main__":
main(True)
sleeper(1.0)
sys.exit()
February 16, 2015 17:38
Blogger
Building My PC - It Has a Home!
February 13, 2015 15:30
Blogger
Building My First PC - It's Alive!
So my computer is finally up and running. I stayed up last night really late hooking up all the wires, and finally getting the courage to start it up and hope that I didn't plug something in the wrong socket. It all worked and I was able to start the BIOS on the computer and set up the operating system followed by a bunch of drivers. I have now finished downloading League of Legends and this my first game on my computer.
For my monitor I decided that I wanted an LED monitor, so I bought the ASUS VN247 monitor, and so far it looks great. I also am so excited to be running SLI on my computer, because it means that I will be able to push higher graphics on games.
At this time my computer is just sitting on my dinning table, so I will have to find a home for it. That's all for now, thanks for reading!
February 12, 2015 23:46
Blogger
Building My First PC - WIP
So I forgot to take a picture of all my components in their boxes, which I really regret. Anyways, I got all the stuff yesterday and and I started to put it together last night with the help of my friend. He helped me mount most of the big parts to the case.
Now that all the parts are mounted, its just a matter of connecting all the cables to the right place. This is probably the scariest part for me, since I'm afraid that I will accidentally fry my computer. This is what I have so far, I just have to plug in the rest of the cables.
I will make sure to post a picture once everything is hooked up and running. Thanks for reading!
February 11, 2015 01:20
Blogger
Mixed Animal Bust # 2
I decided to get rid of the mane and decided to give it a look more along a dog and a goat. Here is what I have:
February 6, 2015 22:27
Blogger
Fibonacci & Dice - Homework 3 Finished
February 5, 2015 01:18
Blogger
Building My First PC - Part List
Today I bought all my parts from Newegg, here is what I bought:
PCPartPicker part list:
CPU: Intel Core i5-4670K 3.4GHz Quad-Core Processor
Motherboard: Asus Z87-A ATX LGA1150 Motherboard
Memory: G.Skill Ripjaws X Series 8GB (2 x 4GB) DDR3-2133 Memory
Storage: Seagate Barracuda 1TB 3.5" 7200RPM Internal Hard Drive
Video Card: Asus GeForce GTX 660 2GB Video Card (2-Way SLI)
Video Card: Asus GeForce GTX 660 2GB Video Card (2-Way SLI)
Case: Thermaltake Chaser A31 ATX Mid Tower Case
Power Supply: Corsair Builder 750W 80+ Bronze Certified ATX Power Supply
Optical Drive: Samsung SH-224DB/BEBE DVD/CD Writer
Operating System: Microsoft Windows 7 Professional SP1 (OEM) (64-bit)
For now I haven't decided on what kind of monitor I will be using, I decided that I could always buy that locally. My friends that have build their own PCs keep telling me that its not that hard to get it put together, so I hope that they are right.
I will post pictures once I get the stuff, thanks for reading!
February 4, 2015 23:43
Blogger
Fibonacci Speaks Parseltongue
The next homework assignment is divided into two parts, I have to created a Fibonacci generator that will print a list of numbers however long the user wants. And second, I have make a very simple text based Yahtzee game.
While I was in class tonight, I managed finish the first part of the assignment. Here is what I have:
#Assignment003_ChristianMunoz.py
#02/04/2014
import random
import math
import sys
import time
#This function suspends the thread for around 1
def sleeper():
time.sleep(1.0)
def fibonacci():
finalSequence = []
aInt = 0
bInt = 1
count = 0
#Player decides how many digits of the fibonacci sequence they want
amount = eval(input('How many digits of the sequence do you want? (At least 2) '))
print(" ")
#This checks to makes sure the number will always be an interger
amount = math.floor(amount)
#This checks to make sure its a valid entry
if amount < 2:
print("That is not a valid entry!")
print(" ")
fibonacci()
#If the player just wants to see 2 digits then we print them right away
elif amount == 2:
finalSequence.append(aInt)
finalSequence.append(bInt)
print(finalSequence)
#If the entry is valid, then execute code
else:
finalSequence.append(aInt)
finalSequence.append(bInt)
while (count < amount - 2):
tempInt = aInt + bInt
aInt = bInt
bInt = tempInt
finalSequence.append(tempInt)
count = count + 1
print(finalSequence)
print(" ")
playAgain()
#This function will run the next game if the player wants to start again
def playAgain():
decision = input("Would you like to play again? Y/N ")
print(" ")
decision = decision.lower()
if decision == "yes" or decision == "y":
main()
else:
print("See you later!")
sleeper()
sys.exit()
#main function
def main():
playerChoice = eval(input("Press 1 to see the Fibonacci Sequence or 2 for Dice: "))
print(" ")
#This makes sure that the number will always be an integer
playerChoice = math.floor(playerChoice)
#This checks to make sure the entry is a valid entry
if playerChoice < 1 or playerChoice > 2:
print("That is not a valid entry!")
print(" ")
main()
#If the entry was valid, then execute code
elif playerChoice == 1:
print("You have chosen the Fibonacci Sequence!")
print(" ")
fibonacci()
else:
print("You have chosen the Dice game!")
diceGame()
#Starts the sequence
main()
I've been thinking about the Yahtzee game, and I don't think it will be that hard. That's all for now, thanks for reading!
February 3, 2015 22:50
Blogger
Alligator Speed Sculpt
So tonight in my ZBrush class we had a speed sculpt assignment to try and sculpt the alligator from the Peter Pan carton:
The point of the exercise wasn't to get a perfect replica or to get in all the detail. It was more to try and set the main big masses and try to shape it to look like the alligator. I think I did a good job in the short time I had.
At first I kind of panicked because I didn't really know where to start. I decided to start with the eyes and then everything kid of just flowed out of there. I think I did a good job at getting the shape of the head. I plan on coming back to this and getting more work done on it.
That's all for now, thanks for reading!
January 29, 2015 02:52
Blogger
Cards & Dice - Homework 2 Finished
#Assignment002_ChristianMunoz.py
#01/29/2014
import random
import math
import sys
import time
#This function suspens the thread for around 1 second and gives the illusion of loading
def sleeper():
time.sleep(1.0)
#Assigns a random number to the dice
def rollDice():
tempInt = random.randint(1,6)
return tempInt
#make the list of cards
def makeListOfCards(stringOfCards):
listOfCards = stringOfCards.split()
return listOfCards
#shuffle code
def shuffleDeck(inputDecks):
shuffledDeck = []
for i in range(len(inputDecks)):
tempInt = random.randint(0,len(inputDecks) - 1)
shuffledDeck.append(inputDecks.pop(tempInt))
return(shuffledDeck)
#This function will run the card game
def cardGame():
decksToShuffle = eval(input("Enter how many decks you would like to shuffle at once (1-5): "))
#This makes sure that the number will always be an integer
decksToShuffle = math.floor(decksToShuffle)
#This checks to make sure the entry is a valid entry
if decksToShuffle <= 0 or decksToShuffle > 5:
print("That is not a valid entry!")
cardGame()
#If the entry was valid, then execute code
else:
CardSymbols = '''AS AH AD AC
KS KH KD KC
QS QH QD QC
JS JH JD JC
10S 10H 10D 10C
9S 9H 9D 9C
8S 8H 8D 8C
7S 7H 7D 7C
6S 6H 6D 6C
5S 5H 5D 5C
4S 4H 4D 4C
3S 3H 3D 3C
2S 2H 2D 2C'''
listOfCards = makeListOfCards(CardSymbols) * decksToShuffle
print("Shuffling the deck\n.")
sleeper()
print("..")
sleeper()
print("...")
sleeper()
print(shuffleDeck(listOfCards))
playAgain()
#This function will run the dice game
def diceGame():
#List of 5 dice
dice1 = rollDice()
print(".")
sleeper()
dice2 = rollDice()
print("..")
sleeper()
dice3 = rollDice()
print("...")
sleeper()
dice4 = rollDice()
print("....")
sleeper()
dice5 = rollDice()
print(".....")
sleeper()
print("You got:", dice1,dice2,dice3,dice4,dice5)
playAgain()
#This function will run the next game if the player wants to start again
def playAgain():
decision = input("Would you like to play again? Y/N ")
decision = decision.lower()
if decision == "yes" or decision == "y":
main()
else:
print("See you later!")
sleeper()
sys.exit()
#main function
def main():
playerChoice = eval(input("Press 1 to play the card game or 2 for dice: "))
#This makes sure that the number will always be an integer
playerChoice = math.floor(playerChoice)
#This checks to make sure the entry is a valid entry
if playerChoice <= 0 or playerChoice > 2:
print("That is not a valid entry!")
main()
#If the entry was valid, then execute code
elif playerChoice == 1:
print("You have chosen the card game!")
cardGame()
else:
print("You have chosen the dice game!")
diceGame()
#Starts the sequence
main()
January 28, 2015 00:13
Blogger
Mixed Animal Bust # 1
I'm going to continue working on this, thanks for reading!
January 25, 2015 22:42
Blogger
Making & Shuffling a Deck of Cards - Homework 2
Then we also have to created a way for the person running the code decide how many decks to shuffle at once.
Here is what I made:
#Assignment002_ChristianMunoz.py
#01/25/2014
from random import randint
import math
#make the list of cards
def makeListOfCards(stringOfCards):
listOfCards = stringOfCards.split()
return listOfCards
#shuffle code
def shuffleDeck(inputDecks):
shuffledDeck = []
for i in range(len(inputDecks)):
tempInt = randint(0,len(inputDecks) - 1)
shuffledDeck.append(inputDecks.pop(tempInt))
return(shuffledDeck)
#main function
def main():
decksToShuffle = eval(input("Enter how many decks you would like to shuffle at once (1-5): "))
#This checks to make sure the entry is a valid entry
if decksToShuffle <= 0 or decksToShuffle > 5:
print("That is not a valid entry!")
main()
#If the entry was valid, then execute code
else:
CardSymbols = '''AS AH AD AC
KS KH KD KC
QS QH QD QC
JS JH JD JC
10S 10H 10D 10C
9S 9H 9D 9C
8S 8H 8D 8C
7S 7H 7D 7C
6S 6H 6D 6C
5S 5H 5D 5C
4S 4H 4D 4C
3S 3H 3D 3C
2S 2H 2D 2C'''
listOfCards = makeListOfCards(CardSymbols) * decksToShuffle
print(shuffleDeck(listOfCards))
main()
I still have to make another little program that works almost the same way, but with dice. This is all for now, thanks for reading!
January 22, 2015 01:20
Blogger
Learning Python - Homework 1
I have actually taken coding classes in the past and I know my way around Java, JavaScript, and ActionScript. I have also done some stuff on my own on CodeCademy to learn those languages.
Today I turned in my first Python assignment, and I'm really excited for this class. The stuff I will post below isn't complicated at all, but at the end of the semester I will have a full game built on Python.
The assignment was basically to introduce us to Python and learn some basic syntax and make a few conversions with data that the user types on the console. If anyone has some critique, please let me know:
# Assignment001_ChristianMunoz.py
# 01/14/2014
#Function 1 = This function converts Celsius to Fahrenheit
print("This program takes a temperature in Celsius as input and converts it to Fahrenheit")
celsius = eval(input("Please input celsius to be converted: "))
fahrenheit = 9/5 * celsius + 32
print("The temperature is ", fahrenheit, " degrees in Fahrenheit.")
print(' ')
#Function 2 = This function converts Fahrenheit to Celsius
print("This program takes a temperature in Fahrenheit as input and converts it to Celsius")
fahrenheit = eval(input("Please input Fahrenheit to be converted: "))
celsius = (fahrenheit - 32) * 5/9
print("The temperature is ", celsius, " degrees in Celsius.")
print(' ')
#Function 3 = This function converts Radians
print("This program takes an angle in Radians and converts it Degrees")
radians = eval(input("Please input Radians to be converted: "))
degrees = radians * (180 / math.pi)
print("The answer is ", degrees, " in Degrees")
print(' ')
#Function 4 = This function converts Degrees
print("This program takes an angle in Degrees and converts it to Radians")
degrees = eval(input("Plese input degrees to be converted: "))
radians = degrees * (math.pi / 180)
print("The answer is ", radians, " in Radians")
print(' ')
#Function 5 = This function finds two coterminal angles (one + and one -)
print("This program takes an angle in Degrees and finds two coterminal angles (one positive and one negative)")
userInput = eval(input("Please input the angle in Degrees to find coterminal angles: "))
positiveAngle = userInput + 360
negativeAngle = userInput - 360
print("The answers are: ", positiveAngle, " and ", negativeAngle, " in Degrees")
print(' ')
#Function 6 = This function finds a complement and supplement angle
print("This program takes an angle in Degrees and finds the Complement and Supplement angles")
userInput = eval(input("Please input the angle in Degrees to find the complement and supplement angles: "))
if userInput >= 180 or userInput < 0:
complement = 'IMPOSSIBLE'
supplement = 'IMPOSSIBLE'
print("The Complementary angle is ", complement, " and the Supplementary angle is ", supplement, ".")
print(' ')
elif userInput >= 90:
complement = 'IMPOSSIBLE'
supplement = 180 - userInput
print("The Complementary angle is ", complement, " and the Supplementary angle is ", supplement, " in Degrees.")
print(' ')
else:
complement = 90 - userInput
supplement = 180 - userInput
print("The Complementary angle is ", complement, " and the Supplementary angle is ", supplement, " in Degrees.")
print(' ')
Archive
- September 2016
- August 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- November 2014
- October 2014
- September 2014
- August 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010