Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99177

Re: error help import random

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: error help import random
Date 2015-11-20 11:10 -0700
Message-ID <mailman.14.1448043092.2291.python-list@python.org> (permalink)
References <8b0ec311-ab7f-429d-877f-d205ad6008d9@googlegroups.com> <n2nmup$j2n$1@ger.gmane.org>

Show all headers | View raw


On Fri, Nov 20, 2015 at 10:57 AM, Peter Otten <__peter__@web.de> wrote:
> Dylan Riley wrote:
>
>> input("\nPress enter to see your fortune")
>
> Make sure that you run your code with Python 3, not Python 2.

Or if you must use Python 2, use raw_input() instead of input().

>> fortune = random.randrange(6) + 1

Also, you have an off-by-one error here. randrange(6) will give you an
integer between 0 and 5, inclusive (a total of 6 possible values).
Adding 1 will then result in an integer between 1 and 6, inclusive,
but you don't have a case for a value of 6.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

error help import random Dylan Riley <dylan.riley@hotmail.com> - 2015-11-20 09:22 -0800
  Re: error help import random Chris Angelico <rosuav@gmail.com> - 2015-11-21 04:30 +1100
  Re: error help import random Peter Otten <__peter__@web.de> - 2015-11-20 18:57 +0100
  Re: error help import random Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-20 11:10 -0700
  Re: error help import random Terry Reedy <tjreedy@udel.edu> - 2015-11-20 15:15 -0500
    Re: error help import random Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-11-20 23:03 +0000
      Re: error help import random Dylan Riley <dylan.riley@hotmail.com> - 2015-11-20 19:26 -0800
  Re: error help import random Seymore4Head <Seymore4Head@Hotmail.invalid> - 2015-11-20 18:05 -0500

csiph-web