Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
card 21 trick
#11
First off, you don't need to keep quoting a reply.
(Aug-18-2017, 12:27 PM)SummoningZ Wrote: Can anyone show me what this would look like?

What what would look like? Here's the deal, we will gladly help with homework, but we will not do it for you. You need to show us code that you have written, not copied from an existing program. If you want to use his program as a guide, that's fine, as long as you understand what he is doing.

My advice is the best way for you to go is to get a deck of 52 cards and perform the trick, writing down each step as you do it, until the game is done.

For example:
At the start of every new game, you must:
1) shuffle the deck
2) select the first 21 cards from the top of the deck (the remainder are set aside)
3) deal out three cards to create row one
4) repeat for rows 2 - 7
You now have 3 columns with 7 rows each (displayed, so player can see them)
5) Ask the user which column the card is in 

and so on. When done, you will have a fairly good idea of what you have to do and in what order. Again, for example, the first thing is you need to define the "deck", this can be a list of all 52 cards. Next you need to "shuffle" the deck (list) so they are "random", how would you do that, then you need to take the first 21 "cards" from the "deck" to create a "pack", how would you do that. How would you ensure that this only happens once, at the beginning of a new game. Are any of the steps repeated? If so, they are a good candidate for a function. Continue on until you can reveal the eleventh card of the pack as the correct card.

If you run into a problem, post your code (between the code tags) with a specific question. If you are getting an output, what is the output versus what you expect the output to be, if you get an error, post the error in it's entirety (between the error tags).

Again, we are happy to help, but you have to make an effort.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
#12
Im not asking you to do it for me im just asking for some kind of idea of what im doing as all the stuff you are saying means nothing to me.

Pack =["JS","4C","KC","3H","5H","AD","10H","9H","7S","JD","6D","JC","2D","QC","5C","JH","4S","QS","8D","9D","4H"]
First = Pack[0:7]
Second = Pack[7:14]
Third = Pack[14:21]

print("1: " + " ".join([str(Pack) for Pack in First]))
print("2: " + " ".join([str(Pack) for Pack in Second]))
print("3: " + " ".join([str(Pack) for Pack in Third]))
This is what I have done so far, is this how it should look?
#13
Doesn't matter how it looks. Do you get the out put you expect? If not, what did you get and what did you expect to get?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
#14
(Aug-18-2017, 06:41 PM)SummoningZ Wrote: Im not asking you to do it for me im just asking for some kind of idea of what im doing as all the stuff you are saying means nothing to me.

Pack =["JS","4C","KC","3H","5H","AD","10H","9H","7S","JD","6D","JC","2D","QC","5C","JH","4S","QS","8D","9D","4H"]
First = Pack[0:7]
Second = Pack[7:14]
Third = Pack[14:21]

print("1: " + " ".join([str(Pack) for Pack in First]))
print("2: " + " ".join([str(Pack) for Pack in Second]))
print("3: " + " ".join([str(Pack) for Pack in Third]))
This is what I have done so far, is this how it should look?

For starters, printing a list can be easier than making a new list. Instead of print("1: " + " ".join([str(Pack) for Pack in First])), you can do print("1: " + " ".join(First)). It's simpler, and hopefully easier for you to understand.

But aside from that, the Pack only has 21 elements in it. I think the first step would be to have a whole deck, shuffle it, and take the first 21 cards from it as the pack. Something like this (though, you might want to replace itertools with something, so it doesn't look like someone else did it for you :p ):
import itertools
import random

# all four suits
suits = "DCHS"
# all 10 numbers, and also Jack Queen King Ace
numbers = list(map(str, range(2, 11))) + list("JQKA")
# build a full deck of 52 cards
full_deck = ["".join(pair) for pair in itertools.product(numbers, suits)]
print(full_deck)
# shuffle the deck, so it's randomized
random.shuffle(full_deck)
print(full_deck)

# get a pack of the first 21 cards in the shuffled deck
pack = full_deck[:21]
print(pack)
#15
Thank you nilamo.

Ok so now I have this import itertools

import itertools
import random
 
suits = "DCHS"
numbers = list(map(str, range(2, 11))) + list("JQKA")
full_deck = ["".join(pair) for pair in itertools.product(numbers, suits)]
random.shuffle(full_deck)
pack = full_deck[:21]

first = pack[0:7]
second = pack[7:14]
third = pack[14:21]

print("1: " + " ".join(first))
print("2: " + " ".join(second))
print("3: " + " ".join(third))

selection = int(input("> "))
if selection == 1:
  pack.extend(second)
  pack.extend(first)
  pack.extend(third)
elif selection == 2:
  pack.extend(first)
  pack.extend(second)
  pack.extend(third)
elif selection == 3:
  pack.extend(first)
  pack.extend(third)
  pack.extend(second)
  
print("You're thinking of %s" %pack[10])
How do I do the actual trick by choosing the 11th card?
#16
Can anyone help me?
#17
So far, you have written no code on your own, merely copied it.  From your question, it is clear you still have not taken the time to understand how the trick is performed, despite the fact that there are numerous examples that explain and show the information. We want to see your code, not dylanfw or nilamo's code. We already know they are able to write the code.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
#18
I DONT KNOW HOW TO WRITE IN PYTHON DO YOU NOT UNDERSTAND WHAT I AM TRYING TO TELL YOU
#19
If you are just going to plagiarize code then you might as well just take the whole thing and hand it in for your assignment. Which your instructor will find. Based on your comments you had 3 weeks to do this program and you ended up with plagiarized code. None of your own from what we see.

It was initially deceitful to identify that code as your own or not at least instruct us that it was borrowed and not your own. People dont like when they are played as fools.

If it was your own code, then you would at least know how to code a little. As well as have a starting base. But since its not your code, then you dont know what is going on in the code to be able to change it. We are not going to change it for you. You need to start from the ground up. I doubt your instructor would of given you this assignment if they didnt give you the tools to do it. So hence you do know how to code in python. Delete it all and restart. As you are writing the code and asking questions here we will help you finish your assignment.
Recommended Tutorials:
#20
I have tried to understand so stop talking to me like I just wrote something online and just sat back waiting for the answer, I just wanted an idea of what the whole thing looked like so I could develop it myself but I guess that wont be happening. At no point did I say "GIVE ME THE ANSWER IM NOT TRYING THIS MYSELF" I dont know what the answer is to the card trick and everywhere I have looked I dont understand it there either, all I asked you guys was how do you do the actual trick after me going from wiki to some math mom thing I still didn't understand it. All I asked was for someone just to tell me the formula or something so dont say im deceitful for trying to make a very bad version of it for an example when I cant even do that.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Graphics Card Values in a List Muzz 0 2,346 Apr-11-2019, 12:55 PM
Last Post: Muzz
  card dealer school project kalle1234 5 10,966 Jan-05-2019, 09:21 PM
Last Post: ichabod801
  Playing Card Sorting ness828 4 76,101 Feb-05-2018, 09:01 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020