Jump to content

Poker in Python

Go to solution Solved by dom1310df,

I see what you're doing but how would I use the first five new elements from my build_deck() function?

deck[0:5]

will give you the first 5 elements from the deck variable.

 

So you probably want something like this:

http://pastebin.com/fzaedMp3

So I'm working on a lab for my Python class and I'm trying to wrap my head around how functions and lists work. So what I'm trying to do is create a hand for five card poker. I started by defining a function(build_deck) which creates a deck and shuffles it and it works just fine. Now I'm trying to create a hand from the shuffled list. I have an idea of what to do but not quite sure how the code works

 

I know I want to make it its own function (so create_hand())

 

So now I want to take the first 5 elements of the list that was created from build_deck() and use that as the hand but I don't know how to access the new list created from it and my professor doesn't want us to use "Global"

import random def build_deck():    deck = ["2C","3C","4C","5C","6C","7C","8C","9C","TC","JC","QC","KC","AC",            "2D","3D","4D","5D","6D","7D","8D","9D","TD","JD","QD","KD","AD"            "2H","3H","4H","5H","6H","7H","8H","9H","TH","JH","QH","KH","AH"            "2S","3S","4S","5S","6S","7S","8S","9S","TS","JS","QS","KS","AS"]    random.shuffle(deck)    print deck def create_hand()
Link to comment
https://linustechtips.com/topic/470921-poker-in-python/
Share on other sites

Link to post
Share on other sites

-snip-

 

 

You'll want something like one of these

# Option 1, call one function from within anotherdef test(var):	print vardef main():	abc = ['a'],['b'],['c'],['d']	test(abc)if __name__ == '__main__':	main()# Option 2, call one function and store the return as a variable, which you pass to the next functiondef test(var):	print vardef main():	abc = ['a'],['b'],['c'],['d']	return abcif __name__ == '__main__':	result = main()	test(result)

How to create a strong password

Size does not matter; it's how you use it

Link to comment
https://linustechtips.com/topic/470921-poker-in-python/#findComment-6314228
Share on other sites

Link to post
Share on other sites

 

You'll want something like one of these

# Option 1, call one function from within anotherdef test(var):	print vardef main():	abc = ['a'],['b'],['c'],['d']	test(abc)if __name__ == '__main__':	main()# Option 2, call one function and store the return as a variable, which you pass to the next functiondef test(var):	print vardef main():	abc = ['a'],['b'],['c'],['d']	return abcif __name__ == '__main__':	result = main()	test(result)

I see what you're doing but how would I use the first five new elements from my build_deck() function?

Link to comment
https://linustechtips.com/topic/470921-poker-in-python/#findComment-6314282
Share on other sites

Link to post
Share on other sites

I see what you're doing but how would I use the first five new elements from my build_deck() function?

deck[0:5]

will give you the first 5 elements from the deck variable.

 

So you probably want something like this:

http://pastebin.com/fzaedMp3

How to create a strong password

Size does not matter; it's how you use it

Link to comment
https://linustechtips.com/topic/470921-poker-in-python/#findComment-6314327
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×