python的if语句学习中总结(二)

python的if语句学习中总结(二),第1张

python的if语句学习中总结(二)
import random

lotter = random.randint(1,999)

print(">>>>>>>>>>>>>>>>>>>>>>>")
print(f"{lotter}")
print("<<<<<<<<<<<<<<<<<<<<<<<")

num= eval(input("Enter three guess number 111 to 999: "))

# 将随机彩票进行分解
lotter1 = lotter // 100
lotter2 = lotter % 100 // 10
lotter3 = lotter % 100 % 10

#将客户输入的数进行分析
guess1 = num // 100
guess2= num % 100 //10
guess3= num % 100 % 10

if num == lotter:
    print("Good luck! Your luck guest give your 100000 dollars!")
elif num != lotter:
    print("Sorry next continu....!")


elif guess1 and guess3 and guess2 == lotter1 and lotter2 and lotter3:
    print("Ha!Ha!,give you 3000 dollars")
elif guess2 and guess3 and guess1 == lotter1 and lotter2 and lotter3:
    print("Ha!Ha!,give you 3000 dollars")
elif guess3 and guess2 and guess1 == lotter1 and lotter2 and lotter3:
    print("Ha!Ha!,give you 3000 dollars")
elif guess2 and guess1 and guess3 == lotter1 and lotter2 and lotter3:
    print("Ha!Ha!,give you 3000 dollars")
elif guess3 and guess1 and guess2 == lotter1 and lotter2 and lotter3:
    print("Ha!Ha!,give you 3000 dollars")

elif guess1 or guess2 or guess3 == lotter1 or lotter2 or lotter3:
    print("Woo! 1000 dollas!")
请同学注意下面这段(这是修改完正确的)
if num == lotter:
    print("Good luck! Your luck guest give your 100000 dollars!")
elif num != lotter:
    print("Sorry next continu....!")
开始的时候我是把elif这段话放到整个程序的后面。程序和结果见下面

大家看到了吧按程序设想和彩票号不一致是应该打印 print(“Sorry next continu…!”) 但是却没有,经过今天上午第一个问题的出现。我开始考虑这个if和elif之间的关系。或者说现在考虑的是关系。 后来我将num != lotter的条件调整了位置,请看上面的正确的位置。if和elif不要分离的太远。num等于和不等于lotter这是一组if和elif。 不知道我这个问题对大家是否有帮助。多多指教。就当是抛砖引玉吧·

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5625070.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存