我如何使输入的图像输出几率很小

问题描述 投票:0回答:1

例如:

                        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是我上传至计算机的恐怖图像。

python loops if-statement statements
1个回答
0
投票

您可以使用随机库

import random
if random.randint(0, 10) == 0:
    print("only ten perecent chance of this happening")

random.randint在两个数字之间选择一个随机数。因为它只有10%的机会选择0,所以它只有10%的打印机会。

您可以在使用os.system之前先在代码中使用它,然后放置if这样的语句。

希望这能回答您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.