python学习第二天--实验总结--筛子

实验筛子:涉及使用知识点:1.input的使用num = input('your money :'+str(ffnum)+':how much do you want bet?:')2.队列point1=random.randrange(1,7)point2=random.randrange(1,7)point3=random.randrange(1,7)a_list=[point1,point2,point3]random.randrange的使用point3=random.ra
摘要由CSDN通过智能技术生成

实验筛子:
涉及使用知识点:
1.input的使用
num = input('your money :'+str(ffnum)+':how much do you want bet?:')

2.队列

point1=random.randrange(1,7)
point2=random.randrange(1,7)
point3=random.randrange(1,7)
a_list=[point1,point2,point3]
  1. random.randrange的使用
point3=random.randrange(1,7)
  1. And 和 or
if summer > 10 and summer <19:

and 即 && or 即 ||

  1. 需要注意point1是数字,输出时,需要转换为字符串,使用str()
 print('the points are[' + str(point1) + ',' +  str(point2) + ',' +  str(point3)+’]’]


7. `if guess ==  'big':`
每一个关键字(例如if else elif while )后,需要加上‘:’

代码:

```handlebars
import random
ffnum =1000
while ffnum > 0:
    point1=random.randrange(1,7)
    point2=random.randrange(1,7)
    point3=random.randrange(1,7)
    a_list=[point1,point2,point3]
    summer=sum(a_list)
    print('<<game starts>>')
    print('Big or small:')
    guess = input('')
    num = input('your money :'+str(ffnum)+':how much do you want bet?:')
    print('<<role the dice>>')
    if summer > 10 and summer <19:
        if guess ==  'big':
            print('the points are ['+str(point1)+','+str(point2)+','+str(point3)+']:you win '+str(num)+',you have ' +str(ffnum+int(num))+' now')
        else:
            print('the points are[' + str(point1) + ',' +  str(point2) + ',' +  str(point3) + ']:you lose'+str(num)+',you have ' +str(ffnum-int(num))+' now')
    else:
        if guess == 'small':
            print('the points are[' +  str(point1) + ',' +  str(point2) + ',' +  str(point3) + ']:you win'+str(num)+',you have ' +str(ffnum+int(num))+'now')
        else:
             print('the points are[' +  str(point1) + ',' +  str(point2) + ',' +  str(point3) + ']:you lose'+str(num)+',you have ' +str(ffnum-int(num))+' now')

预计实现效果:
结果

参考代码:

1  import random 
2  def roll_dice(numbers=3, points=None):                 
3      print('<<<<< ROLL THE DICE! >>>>>')            
4      if points is None:                                      
5          points = []                                         
6     while numbers > 0:                                 
7         point = random.randrange(1,7)                
8         points.append(point)                       
9         numbers = numbers - 1                         
10    return points

1  def roll_result(total):                                     
2      isBig = 11 <= total <=18                                 
3      isSmall = 3 <= total <=10                                
4      if isBig:                                               
5         return 'Big'                                        
6      elif isSmall:                                           
7          return 'Small'

1  def start_game(): 
2      print('<<<<< GAME STARTS! >>>>>') 
3      choices = ['Big','Small'] 
4      your_choice = input('Big or Small :') 
5      if your_choice in choices: 
6   points = roll_dice() 
7   total = sum(points) 
8   youWin = your_choice == roll_result(total) 
9   if youWin: 
10   print('The points are',points,'You win !')      
11         else: 
12  print('The points are',points,'You lose !')     
13     else: 
14  print('Invalid Words') 
15  start_game() 16 start_game()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值