|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random#
a=random.randint(1,2)
b=random.randint(1,2)
aim=[str(a),str(b)]
times=6
temp=[input("输入你认为中奖的第一个数字: "),input("输入你认为中奖的第二个数字: ")]
x=temp[0]
y=temp[1]
while times>0:
if x not in aim and y not in aim:
print("十分遗憾,没有中奖哦。。")
print("你还有"+str(times)+"机会。")
temp=[input("输入你认为中奖的第一个数字: "),input("输入你认为中奖的第二个数字: ")]
times-=1
elif x in aim and y not in aim:
print("恭喜,你中了三等奖!!")
print("你还有"+str(times)+"机会。")
temp=[input("输入你认为中奖的第一个数字: "),input("输入你认为中奖的第二个数字: ")]
times-=1
elif y in aim and x not in aim:
print("恭喜,你中了三等奖!!")
print("你还有"+str(times)+"机会。")
temp=[input("输入你认为中奖的第一个数字: "),input("输入你认为中奖的第二个数字: ")]
times-=1
elif [x,y]==aim.reverse():
print("恭喜,你中了二等奖!!")
print("你还有"+str(times)+"机会。")
temp=[input("输入你认为中奖的第一个数字: "),input("输入你认为中奖的第二个数字: ")]
times-=1
elif [x,y]==aim:
print("恭喜,你中了一等奖!!")
print("你还有"+str(times)+"机会。")
temp=[input("输入你认为中奖的第一个数字: "),input("输入你认为中奖的第二个数字: ")]
times-=1
if times==0:
print("抽奖机会用完了,再充值100元给10次机会哦!")
输入你认为中奖的第一个数字: 4
输入你认为中奖的第二个数字: 4
十分遗憾,没有中奖哦。。
你还有6机会。
输入你认为中奖的第一个数字: 1
输入你认为中奖的第二个数字: 1
十分遗憾,没有中奖哦。。
你还有5机会。
输入你认为中奖的第一个数字: 1
输入你认为中奖的第二个数字: 2
恭喜,你中了一等奖!!
你还有6机会。
输入你认为中奖的第一个数字: 4
输入你认为中奖的第二个数字: 4
恭喜,你中了一等奖!!
你还有5机会。
输入你认为中奖的第一个数字:
但输出结果是这样的,哪里循环错了么,新手昨天刚刚看到函数,编的有点长
每次重新输入temp 你没有把 x y 重新赋值 导致你只要第一次输入正确 后面每次都是正确的值,你要在每行
的temp 下对 x y 进行重新赋值
- import random #
- a = 1
- b = 1
- # a = random.randint(1, 2)
- # b = random.randint(1, 2)
- aim = [str(a), str(b)]
- times = 6
- temp = [input("输入你认为中奖的第一个数字: "), input("输入你认为中奖的第二个数字: ")]
- x = temp[0]
- y = temp[1]
- while times > 0:
- if x not in aim and y not in aim:
- print("十分遗憾,没有中奖哦。。")
- print("你还有" + str(times) + "机会。")
- temp = [input("输入你认为中奖的第一个数字: "), input("输入你认为中奖的第二个数字: ")]
- x = temp[0]
- y = temp[1]
- times -= 1
- elif x in aim and y not in aim:
- print("恭喜,你中了三等奖!!")
- print("你还有" + str(times) + "机会。")
- temp = [input("输入你认为中奖的第一个数字: "), input("输入你认为中奖的第二个数字: ")]
- x = temp[0]
- y = temp[1]
- times -= 1
- elif y in aim and x not in aim:
- print("恭喜,你中了三等奖!!")
- print("你还有" + str(times) + "机会。")
- temp = [input("输入你认为中奖的第一个数字: "), input("输入你认为中奖的第二个数字: ")]
- x = temp[0]
- y = temp[1]
- times -= 1
- elif [x, y] == aim.reverse():
- print("恭喜,你中了二等奖!!")
- print("你还有" + str(times) + "机会。")
- temp = [input("输入你认为中奖的第一个数字: "), input("输入你认为中奖的第二个数字: ")]
- x = temp[0]
- y = temp[1]
- times -= 1
- elif [x, y] == aim:
- print("恭喜,你中了一等奖!!")
- print("你还有" + str(times) + "机会。")
- temp = [input("输入你认为中奖的第一个数字: "), input("输入你认为中奖的第二个数字: ")]
- x = temp[0]
- y = temp[1]
- times -= 1
- if times == 0:
- print("抽奖机会用完了,再充值100元给10次机会哦!")
复制代码
|
|