python 3.x - How can i use a string to determine the location of an object within a list? -
let's have list of alphabet
mylist=["a","b","c"..."z"]
now lets have variable within loop takes out random letter list. random imported.
while true: ans=mylist[random.randint(1,26)]
i want user asked take guess @ letter within loop add
guess=input('take guess @ letter alphabet')
the user receive clue on whereabouts of answer
print('the letter locates between x , x.')
question. how can determine position of ans
in mylist
can give 2 random values , perhaps assign them variables, 1 below ans
, 1 value on ans
.
the range
random between these 2 values ans
not median of 2 values.
p.s. put script give better view of looks like, unfortunately find formatting confusing, , highlighting pieces of code , pressing ctrl+k not work expected.
the position output of random call, right?
you can save variable before calling mylist[]
index = random.randint(1,26) ans = mylist[index]
Comments
Post a Comment