擅长:python、mysql、java
<p>在每个if语句中,您将获得一个新的随机字母。有一种可能,新的选择不会是你正在比较的字母,甚至可能是你每次都在比较的字母。没办法知道。如果您只想从列表中获得一个随机字母,并根据它是哪个字母来执行某些操作,请将其存储在变量中,并在If语句中使用该变量。你知道吗</p>
<pre><code>import random
mylist = ["a", "b", "c"]
mynums = ["1","2","3"]
myint = ["6","7","8"]
letterChoice = random.choice(mylist)
if letterChoice == "a":
print ("a")
numberChoice = random.choice(mynums)
print (numberChoice)
if letterChoice == "b":
print ("b")
intChoice = random.choice(myint)
print (intChoice)
if letterChoice == "c":
print ("c")
</code></pre>