年近半百自学Python之掷骰子游戏
循环结构的练习:
掷骰子(🈸)
两个:1--6
1.玩游戏要有金币,没有则不能玩游戏
2.玩游戏赠金币1枚,充值获取金币
3.充(🕑)值为10元的倍数,送20个金币
4.玩游戏消耗5个金币
5.猜大小:猜对 鼓励金2枚 猜错没有奖励
6.游戏结束:1.主动退出 2.没(📳)有金币退出
7.只要退出则打印金币(☕)数,共玩了几局(♟)
--------------------------------
import random
#金(🎖)币数
coins=0
#玩(📁)的次数
count=0
if coins<5:
--- #提示充值
---print('金币不足请充值再玩(🍮)!')
---while True:
------money=int( input('请输入充值金额:'))
------#10元的倍数,20个金币
------if money%10==0:
---------coins+=money//10*20
---------print('充值成功!当(🐙)前金币有%d个' %coins)
---------#开启游戏之旅
---------print(’~~~~~~~开启游戏之旅(🔑)~~~~~~~')
---------answer=input(’是否开始游戏(y/n)?')
---------while coins>5 and answer=='y’:
-----------#扣金币
-----------coins-=5
-----------#赠送金币
-----------coins+=1
-----------#产(🌍)生两枚随(🥙)机的骰子数
--------ran1=random.randint(1,6)
--------ran2=random.randint(1,6)
----------#猜大小
----------guess=input('洗牌完毕,请猜大小:')
----------#判断比较
----------if guess=='大' and ran1+ran2>6 or guess=='小' and ran1+ran2<=6:
------------print(‘恭喜猜对了,你赢了!')
------------coins+=2
----------else:
-------------print(‘很遗(🐺)憾!猜错了!')
----------count+=1
----------answer=input('是否继续游戏(y/n)?‘)
------#打印次数 金币(👼)数
------print('共玩了%d次,剩(🌪)余金币:%d' %(count,coins))
------break
---else:
------print(‘不(➰)是10的倍数,充值失败!')