Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.randrange
#11
(Mar-17-2019, 03:08 PM)ravioli2929 Wrote: unfortunately i cant use the for or in functions as it is homework.

Just asking how would I ask for more than one value say I
wanted 6 different random letters (there can be a duplicate)

So no for or in (BTW - these are keywords, not functions); what about while? Smile

But basically it's six times same, you must fit it into constraints of assignment:


import random
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz"
first = alphabet[random.randrange(len(alphabet))]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#12
deos first refer to the first letter
Reply
#13
(Mar-17-2019, 04:20 PM)ravioli2929 Wrote: deos first refer to the first letter

It refers to first random letter in alphabet. As I understand you need six of them.

random.randrange(len(alphabet)) gives you integer which is in range of valid alphabet indexes. You use this value as index and it returns you a random letter (as index is selected randomly the letter is also random)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#14
ive got it to generate a word
but the output comes out like this
EX:
s X g d F g a
how do i make it like this:
sXgdFga
would it be the sep = "" ??
Reply
#15
(Mar-17-2019, 04:33 PM)ravioli2929 Wrote: would it be the sep = "" ??

You can test it in interactive interpreter in no time. If result don't suit you then ask question about it.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,428 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Remove space after random.randrange(1, 11) rs74 4 2,266 Jun-06-2020, 07:46 AM
Last Post: rs74

Forum Jump:

User Panel Messages

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