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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -