【Python】猜数小程序

有点沙雕

temp=input("猜猜我心里想的是哪个数字?")guess=int (temp)if guess==8: print("你是我肚里的蛔虫么?") print("哼,猜中也没有奖励")else: print("哈哈,猜错了哦!是8") print("游戏结束,不玩了!")

PS:代码缩进很重要!

升级版1.0 if嵌套

temp=input("猜猜我心里想的是哪个数字?")guess=int (temp)if guess==8: print("你是我肚里的蛔虫么?") print("哼,猜中也没有奖励")else: if guess<8: print("小啦~") else: print("大啦~")print("游戏结束,不玩了!")

 升级版2.0 循环

【Python】猜数小程序
#三次机会counts=3#循环while counts>0: temp=input("猜猜我心里想的是哪个数字?只有三次机会哦!n") guess=int (temp) if guess==8: print("你是我肚里的蛔虫么?") print("哼,猜中也没有奖励") else: if guess<8: print("小啦~") else: print("大啦~") counts=counts-1print("游戏结束,不玩了!")

注意:代码缩进很重要的!

相关文章