- 1
A problem on python
Hi guys i wanna write a python programme that randomly selects a name from a list of names and prints out questions for the selected name and after each question and answer session with a selected name it continues with other names till all the names in the list are gotten. And lastly it prints the most answered question. Pls some one should just give me a prototype cos I'm new to python.
3 Answers
+ 2
you have broke down what you want to do, that's the hardest part. keep moving forward. where would I start?
Make a list... names=[]
make variables to keep track of the number of times answers are given
blue=0
red=0
whatever..
write a function to randomly select a name from the list and then remove it from the list
def getname():
name= random.choice(names)
names.remove(name)
return name
encase everything in a while loop so when your done questioning the first name it loops back to the function to get another name.
you can do this, I won't write the program for you, but I'm you make efforts and need help with bits of your code we will gladly help. take it 1 piece at a time
+ 1
your question takes too much time to code, so instead I'll just give you the functions you'll need.
import random (place this in the beginning of your code to import the random library, you need it to ask the program to pick a "random" name)
random.pick(yourlistofnames) (this picks a random element from a list)
(yourlistofnames).remove("a_name") (put an element of the list instead of "a_name" to remove that element)
now for the next part of your question; you want the program to tell you which question was mostly answered correctly.. for that I would suggest creating a dictionary (check what a dictionary is if you don't know already) in which every key is the question's number, and it's value is how much it's been answered correctly, after the program is done, print the key of the question that has the highest "correct answer" rate.. hope this helps
- 1
thanks ramzi and hill actually you can forget about printing the mostly answered question cos that makes the code unnecessarily complex. what i really want to know now is how to associate the questions with the randomly picked name.... which definitely should come after the function and whats the reason for the remove code.