栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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。 不知道我这个问题对大家是否有帮助。多多指教。就当是抛砖引玉吧·
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/618994.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号