So I’m really new to programming, I just started learning Python yesterday and I’m having a little trouble. I’ve looked through a few tutorials and haven’t come up with how to answer my question on my own, so I’m coming to you guys.
quickList = ["string1", "string2"]
anotherList1 = ["another1a", "another1b"]
anotherList2 = ["another2a", "another2b"]
for i in range(1):
quick=random.choice(quickList)
another1=random.choice(anotherList1)
another2=random.choice(anotherList2)
What I want to do is write the code so that if quick turns up string1, it will print string1 and then print another1, but if quick generates string2, it will print string2 and then an entry from anotherList2.
Any hints?
Thanks in advance for your help!
Since you’re new to Python, let me suggest another way of doing this.
Also as others have mentioned, not sure why your code is in a
forloop. You could take that out as well, but I have left it in for this example.This let’s you expand your list more easily and saves you from building a bunch of
ifstatements. It could be further optimized, but try and see if you understand this approach 🙂