Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54874
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.022 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:sample': 0.09; 'def': 0.12; 'translation': 0.12; 'random': 0.14; '0):': 0.16; 'cards.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; '8bit%:5': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'math': 0.24; 'nearly': 0.26; 'header:X-Complaints-To:1': 0.27; 'code': 0.31; 'correctly.': 0.31; 'url:python': 0.33; 'could': 0.34; 'created': 0.35; 'but': 0.35; 'c++': 0.36; 'false': 0.36; 'url:org': 0.36; 'list': 0.37; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; '8bit%:6': 0.40; 'break': 0.61; 'url:3': 0.61; 'entire': 0.61; 'email addr:gmail.com': 0.63; 'card': 0.63; 'cards': 0.65; 'containing': 0.69; 'cards,': 0.84; 'dealer,': 0.84; 'repeat.': 0.84; 'subject:card': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re: card dealer |
| Date | Fri, 27 Sep 2013 11:26:21 +0000 (UTC) |
| References | <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | 174.32.174.35 |
| User-Agent | XPN/1.2.6 (Street Spirit ; Linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.376.1380281201.18130.python-list@python.org> (permalink) |
| Lines | 64 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1380281201 news.xs4all.nl 15902 [2001:888:2000:d::a6]:45737 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:54874 |
Show key headers only | View raw
On 27/9/2013 06:24, markotaht@gmail.com wrote:
> from random import *
> from math import floor
>
>
> kaarte_alles = 52
> kaart_tõmmatud = [False for i in range(52)]
>
>
> mast = ["ärtu", "ruutu", "poti", "risti"]
> aste = ["äss", "kaks", "kolm", "neli","viis", "kuus", \
> "seitse", "kaheksa", "üheksa", "kümme", "soldat",\
> "emand", "kuningas"]
>
> def tõmba_kaart():
> global kaarte_alles
> if kaarte_alles == 0:
> print("Segan pakki")
> kaarte_alles = 52
> for i in range(52):
> kaart_tõmmatud[i] = False
> kaarte_alles -= 1
> n = random(kaarte_alles)
> kaart = vali_järgmine_vaba(n)
> m = kaart % 13
> a = kaart / 13
> print(mast[int(a)] + " " + aste[int(m)])
>
> def vali_järgmine_vaba(n):
> i = -1
>
> while(n > 0):
> n -= 1
> i = i + 1
> while kaart_tõmmatud[i]:
> i = i + 1
> kaart_tõmmatud[i] = True
> return i
>
> def random(n):
> return randint(0, n)
>
> while True:
> n = int(input("Mitu kaarti tõmmata(0 et väljuda): "))
> if(n==0):
> break
>
> for i in range(n):
> tõmba_kaart()
>
>
> HI im trying to make a card dealer, but this code doesent work correctly. It deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the same cards. This is a translation from my c++ code. In c++ it works correctly.
If you had created your global list containing list(range(52)), then you
could do nearly your entire program with one call to random.sample.
http://docs.python.org/3.3/library/random.html#random.sample
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
card dealer markotaht@gmail.com - 2013-09-27 03:24 -0700
Re: card dealer Dave Angel <davea@davea.name> - 2013-09-27 11:26 +0000
Re: card dealer MRAB <python@mrabarnett.plus.com> - 2013-09-27 12:27 +0100
Re: card dealer Alister <alister.ware@ntlworld.com> - 2013-09-27 11:41 +0000
Re: card dealer Dave Angel <davea@davea.name> - 2013-09-27 12:08 +0000
Re: card dealer Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-27 16:10 +0000
Re: card dealer Dave Angel <davea@davea.name> - 2013-09-27 21:00 +0000
Re: card dealer Ned Batchelder <ned@nedbatchelder.com> - 2013-09-27 17:40 -0400
Re: card dealer Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-28 06:01 +0000
Re: card dealer Ned Batchelder <ned@nedbatchelder.com> - 2013-09-28 06:31 -0400
Re: card dealer Dave Angel <davea@davea.name> - 2013-09-28 12:56 +0000
Re: card dealer Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-28 16:49 +0200
Re: card dealer Tim Roberts <timr@probo.com> - 2013-09-28 17:04 -0700
csiph-web