1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import random
lottery = random.randint(100, 999) user_num = int(input("请输入一个三位数:"))
if user_num == lottery: print(f"恭喜你,你中了$10,000,彩票号码是{lottery}。") else: lot_digits = [lottery // 100, (lottery // 10) % 10, lottery % 10] user_digits = [user_num // 100, (user_num // 10) % 10, user_num % 10] same = [d for d in user_digits if d in lot_digits] if len(same) == 3: print(f"恭喜你,你中了$3,000,彩票号码是{lottery}。") else: match_count = sum(1 for d in user_digits if d in lot_digits) if match_count > 0: print(f"恭喜你,你中了$1,000,彩票号码是{lottery}。") else: print(f"很遗憾,你没有中奖。彩票号码是{lottery}。")
|