Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59297
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '"""': 0.07; 'subject:help': 0.08; '75,': 0.09; 'escape': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '2.7': 0.14; 'random': 0.14; '"does': 0.16; "(i'm": 0.16; 'ans': 0.16; 'helps.': 0.16; 'nest': 0.16; 'pairs': 0.16; 'pygame': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'simplified': 0.16; 'them.)': 0.16; 'tuple': 0.16; 'unpacking': 0.16; 'wrote:': 0.18; 'input': 0.22; 'import': 0.22; 'putting': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; "i've": 0.25; 'define': 0.26; 'header:X-Complaints-To:1': 0.27; 'michael': 0.29; "i'm": 0.30; 'code': 0.31; 'tuples': 0.31; 'running': 0.33; 'skip:# 10': 0.33; 'could': 0.34; 'subject:with': 0.35; 'case,': 0.35; 'but': 0.35; 'really': 0.36; 'list': 0.37; 'question,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'hope': 0.61; 'lower': 0.61; 'kind': 0.63; 'more': 0.64; 'upper': 0.74; 'subject:this': 0.83; 'answer:': 0.84; 'imran': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Please help with this |
| Date | Wed, 13 Nov 2013 13:30:16 +0100 |
| Organization | None |
| References | <6ade7311-fe93-4747-959b-e9b947714b00@googlegroups.com> <89009d07-acb3-4c62-855b-2a25f0487125@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p50848fa0.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| 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.2531.1384345789.18130.python-list@python.org> (permalink) |
| Lines | 82 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1384345789 news.xs4all.nl 15924 [2001:888:2000:d::a6]:41887 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:59297 |
Show key headers only | View raw
mkharper wrote:
> Hi Saad,
>
> I've had a play and the following "does something".
> (I'm running Python 2.7 so replaced input with raw_input.)
> (User can use upper or lower case, just lower it before test.)
> (I simplified the questions/answers so I could answer them.)
>
> I'm out of time but hope the following helps.
>
> Kind regards,
>
>
> Michael
>
>
> #!/usr/bin/env python
> """
> This is a game where you have to escape a dragon.
> By Saad Imran
>
> """
>
> import random
> import pygame
>
> # Define questions and answers.
>
> QUE = {1: "4 x 2",
> 2: "3 x 6",
> 3: "2 x 5",
> 4: "6 / 2",
> 5: "7 + 7",
> 6: "8 - 3",
> 7: "5 x 5",
> 8: "4 / 1",
> 9: "0 x 6", }
>
> ANS = {1: "8;75;75",
> 2: "18;75;75",
> 3: "10;75;75",
> 4: "3;75;75",
> 5: "14;75;75",
> 6: "5;75;75",
> 7: "25;75;75",
> 8: "4;75;75",
> 9: "0;75;75", }
>
> # Code to generate random number
> QUESEL = random.randrange(1, 10)
You can simplify that some more by putting question/answer pairs into a list
qa_pairs = [
("What is 4 x 2? ", "8"),
("What is 3 x 6? ", "18"),
#...
]
and then use random.choice() and tuple unpacking
question, answer = random.choice(qa_pairs)
if input(question) == answer: # python 2: replace input with raw_input
print("correct")
else:
print("UH-OH!")
You can nest the tuples if you really need other data
qa_pairs = [
("What is 4 x 2? ", ("8", 75, 75)),
("What is 3 x 6? ", ("18", 75, 75)),
#...
]
question, answer_and_offset = random.choice(qa_pairs)
answer, userx, dragonx = answer_and_offset
#...
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Please help with this saad imran <saad.imran98@gmail.com> - 2013-11-12 20:18 -0800
Re: Please help with this Gary Herron <gary.herron@islandtraining.com> - 2013-11-12 20:34 -0800
Re: Please help with this Ben Finney <ben+python@benfinney.id.au> - 2013-11-13 16:54 +1100
Re: Please help with this Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-13 06:02 +0000
Re: Please help with this Dave Angel <davea@davea.name> - 2013-11-13 00:45 -0600
Re: Please help with this Steven D'Aprano <steve@pearwood.info> - 2013-11-13 06:49 +0000
Re: Please help with this mkharper <mkharper@gmail.com> - 2013-11-13 00:53 -0800
Re: Please help with this mkharper <mkharper@gmail.com> - 2013-11-13 01:02 -0800
Re: Please help with this mkharper <mkharper@gmail.com> - 2013-11-13 03:09 -0800
Re: Please help with this Peter Otten <__peter__@web.de> - 2013-11-13 13:30 +0100
csiph-web