Problems with python random module | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problems with python random module

i have a program that randomly selects a name from a list of names and asks the selected person some questions. how do i tell the program to associate the randomly chosen name to the question. E.g if chris was the chosen name how do i associate his name with his question. this also applies to other names. and finally i would like to enclose this in a loop and also print the most reoccurring answers from different people at the end.

21st Feb 2017, 11:59 AM
Prince Kelvin
Prince Kelvin - avatar
5 Answers
+ 7
#I assume you mean something like this import random namelist=["chris","zyra","sona"] name= random.choice(namelist) question="what's your favorite color" print(question,name,"?")
21st Feb 2017, 12:41 PM
Ahri Fox
Ahri Fox - avatar
+ 7
add to it in what way? theres lots of ways depending on what you mean. like name="prince" print("what the heck do you mean, %s?" % name) or name="princess" list=["so",name,"wanna go out on a date with me?"] print(" ".join(list))
22nd Feb 2017, 12:53 AM
Ahri Fox
Ahri Fox - avatar
0
yes but for some reason it doesn't seem to work
21st Feb 2017, 3:28 PM
Prince Kelvin
Prince Kelvin - avatar
0
but i dont wanna make the question a variable i just wanna add the name to the question
21st Feb 2017, 3:30 PM
Prince Kelvin
Prince Kelvin - avatar
0
Ahri thanks problem sorted out
23rd Feb 2017, 9:00 PM
Prince Kelvin
Prince Kelvin - avatar