1. python random模块

1. python random

1. random

  • random.randint 指定一个范围随机返回这个范围内的数
  • random.choice 随机返回列表或元组中的一个值

randint

from random import randint

print(randint(1,6))

choice

"""使用random模块中的choice方法制作一个彩票分析小程序,看看中彩票有多难!"""

from random import choice

my_ticket = (2,'b','b','e')
caipiao = [1,2,3,4,5,6,7,8,9,'a','b','c','d','e']

a = 0
while True:
    number = []
    for i in range(4):
        number.append(random.choice(caipiao))
    tuple1 = tuple(number)
    print(f"您抽中的号码为:{tuple1}")
    a += 1
    if tuple1 == my_ticket:
        print(f"恭喜您中奖啦!!! 本次中奖号码为: {my_ticket},请核实您抽中的号码")
        print(f"a = {a}")
        break
posted @ 2025-02-24 13:53  逃离这世界~  阅读(34)  评论(0)    收藏  举报