【python核心编程第二部】7.14

import random#随机数模板

A=set()#声明两个集合存放生成的随机数
B=set()

for step in range(random.randint(1,10)):#决定有几个随机数
    A.add(random.randint(0,9))#决定这几个随机数是什么

for step in range(random.randint(1,10)):
    B.add(random.randint(0,9))

print("set A:",A)
print("set B:",B)

unioninput=set([int(n) for n in input("please input A|B :").split()])#存储输入的A|B
andinput=set([int(n) for n in input("please input A&B:").split()])#存储输入的A&B

for a in range(0,3):
    if A|B==unioninput and A&B==andinput:#若两个输入均正确
        print("You are right!")
    elif a==2:#第三次仍输入不正确时
        print("Sorry, you are wrong:")
        print("A|B:",A|B)
        print("A&B:",A&B)
    else:#前两次输入不正确时
        print("Sorry, you are wrong:")
        unioninput=set(input("please input A|B again :"))
        andinput=set(input("please input A&B again:"))
    

  

posted @ 2018-10-23 20:33  洞幺先生  阅读(86)  评论(0)    收藏  举报