1. 程式人生 > >使用Python買福彩,5個數字,20選5,有沒買過

使用Python買福彩,5個數字,20選5,有沒買過

import random,sys,os
num = random.sample(range(1,21),5)
print(num)
f=open("haha.txt","a+")
f.write(str(num)+"\n")
f.close()
person1 = int(input('請輸入你要買的數字:'))
person2 = int(input('請輸入你要買的數字:'))
person3 = int(input('請輸入你要買的數字:'))
person4 = int(input('請輸入你要買的數字:'))
person5 = int(input('請輸入你要買的數字:'))
if person1 > 20 or person2 > 20 or person3 > 20 or person4 > 20 or person5 > 20:
print("不能輸入大於20的數字")
sys.exit()
if person1 == person2 or person1 == person3 or person1 == person4 or person1 == person5 or person2 == person3 or person2 == person4 or person2 == person5 or person3 == person4 or person3 == person5 or person4 == person5:
print("不能購買重複的號碼")
sys.exit()
if person2 in num and person3 in num and person4 in num and person5 in num and person1 in num:
print("恭喜你,全中了,獎勵320元")
if person1 in num:
if person2 not in num and person3 not in num and person4 not in num and person5 not in num:
print("中了一個,很遺憾沒獎勵")
if person2 in num and person3 not in num and person4 not in num and person5 not in num:
print("中了兩個,很遺憾沒獎勵")
if person2 in num and person3 in num and person4 not in num and person5 not in num:
print("中三個,很遺憾沒獎勵")
if person2 in num and person3 in num and person4 in num and person5 not in num:
print("中四個,很遺憾沒獎勵")
if person2 in num:
if person1 not in num and person3 not in num and person4 not in num and person5 not in num:
print("中了一個,很遺憾沒獎勵")
if person1 in num and person3 not in num and person4 not in num and person5 not in num:
print("中了兩個,很遺憾沒獎勵")
if person1 in num and person3 in num and person4 not in num and person5 not in num:
print("中三個,很遺憾沒獎勵")
if person1 in num and person3 in num and person4 in num and person5 not in num:
print("中四個,很遺憾沒獎勵")
if person3 in num:
if person1 not in num and person2 not in num and person4 not in num and person5 not in num:
print("中了一個,很遺憾沒獎勵")
if person1 in num and person2 not in num and person4 not in num and person5 not in num:
print("中了兩個,很遺憾沒獎勵")
if person1 in num and person2 in num and person4 not in num and person5 not in num:
print("中三個,很遺憾沒獎勵")
if person1 in num and person2 in num and person4 in num and person5 not in num:
print("中四個,很遺憾沒獎勵")
if person4 in num:
if person1 not in num and person2 not in num and person3 not in num and person5 not in num:
print("中了一個,很遺憾沒獎勵")
if person1 in num and person2 not in num and person3 not in num and person5 not in num:
print("中了兩個,很遺憾沒獎勵")
if person1 in num and person2 in num and person3 not in num and person5 not in num:
print("中三個,很遺憾沒獎勵")
if person1 in num and person2 in num and person3 in num and person5 not in num:
print("中四個,很遺憾沒獎勵")
if person5 in num:
if person1 not in num and person2 not in num and person3 not in num and person4 not in num:
print("中了一個,很遺憾沒獎勵")
if person1 in num and person2 not in num and person3 not in num and person4 not in num:
print("中了兩個,很遺憾沒獎勵")
if person1 in num and person2 in num and person3 not in num and person4 not in num:
print("中三個,很遺憾沒獎勵")
if person1 in num and person2 in num and person3 in num and person4 not in num:
print("中四個,很遺憾沒獎勵")
if person1 not in num and person2 not in num and person3 not in num and person4 not in num and person5 not in num:
print("不好意思,一個都沒中,要加油哦")