-3

I am trying to do this

proverbs = "a bad excuse is better than none","A bad workman blames his tools," etc.
number_of_proverb = random.randint (1,38)
proverb = sentence number number_of_proverb

But I have no idea how to assign numbers to sentences. Thank you, beforehand, for all of your help.

PS 38 because there are 38 sentences. Also is this

proverbs = "something something","something something","something, something"

correct? Sorry for these basic questions but I just started.

  • Sorry, could be me being tired, but I actually have no clue what you want to do. Could you clarify? – andrbrue Oct 02 '20 at 22:09
  • Look into python dictionary. And this question - https://stackoverflow.com/questions/36186716/assigning-number-to-word-in-a-string-in-python – Keneni Oct 02 '20 at 22:12
  • Why do you want to assign numbers to sentences? What kind of numbers? Please include the expected output. – DYZ Oct 02 '20 at 22:13
  • 1
    Do you want to map numbers to sentences? You might want to do some research about arrays. – andrbrue Oct 02 '20 at 22:14
  • @andrbrue Hangman with common proverbs. Random generation of these problems. To do that I want to assign numbers to them and chose numbers instead of full sentences. – Zbyszek Radzimił Oct 02 '20 at 22:49
  • @DYZ look how i responded to andrbrue's comment – Zbyszek Radzimił Oct 02 '20 at 22:49
  • @DYZ The expected output are 38 sentences with assigned numbers. – Zbyszek Radzimił Oct 02 '20 at 22:50
  • I suspect you want to have a list of 38 sentences but access them by a number, e.g. you want to say "give me the 7. sentence" or a random one. If this is the case and only into this direction (meaning you do not have a sentence and then want to get its number) you should use lists. I recommend reading some documentation about lists as they are a central topic of programming python. I am still unsure if this solves your problem as it is very difficult to understand your question. – andrbrue Oct 02 '20 at 23:00
  • Does this answer your question? [How to randomly select an item from a list?](https://stackoverflow.com/questions/306400/how-to-randomly-select-an-item-from-a-list) – Robert Hensley Oct 02 '20 at 23:27

2 Answers2

0

I see what you are trying to do. You are making a list of proverbs and you want to randomly select one from a list. So it would be best to store your proverbs in a list and use random.choice to select them from that list.

proverbs = ["this proverb","that proverb","something, something", "another"]

random.choice(proverbs)

If you want to have a number associated with the proverbs, you can just use the index function to get the position of the proverb in the list. Like this:

proverbs.index("another")

Output:

3
0

Thank you Robert and @andrbrue. I did this.

proverbs = ["A bad excuse is better than none.","A bad workman blames his tools."

(there are 38 proverbs)

rp = (proverbs[random.randint(1,38)])

I still have some problems but I'll figure them out. Thx so much