例如:
comm = raw_input("Type something you want to say to me > " )
except: comm = "."
if comm.lower().strip() == "hi":
print "hello"
(10% chance of running this command too) os.system('catimg devil_face.png')
这里,catimg
是一个控制台命令,它将图像转换为ASCII彩色字符,而devil_face.png是我上传至计算机的恐怖图像。
您可以使用随机库
import random
if random.randint(0, 10) == 0:
print("only ten perecent chance of this happening")
random.randint在两个数字之间选择一个随机数。因为它只有10%的机会选择0,所以它只有10%的打印机会。
您可以在使用os.system之前先在代码中使用它,然后放置if这样的语句。
希望这能回答您的问题。