codes = ["A", "B", "C", "D", "E"]
random.shuffle(codes)
def print_message(message):
print "\n"
print "-"*10
print message
print "-"*10
print "\n"
print_message('This is a test of the %s system' % codes[0])
然后,我如何根据出现的随机字母为 print_message('This...') 的结果执行 if 语句。
例子。如果代码 [0] 的结果最终是 print_message() 的“A”,那么您会在屏幕上看到以下内容:
----------
This is a test of the A system.
The A system is really great.
---------
再运行几次命令,你会看到:
----------
This is a test of the C system.
The C system sucks.
----------
----------
This is a test of the B system.
The B system has improved greatly over the years.
----------