| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- #买彩票
 
 - import random
 
 - import math
 
 - red = []
 
 - blue = []
 
 - print('请问老板是玩双色球还是大乐透?')
 
 - print('双色球请输入1,大乐透请输入2。')
 
 - way = int(input('请输入您的选择: '))
 
  
- if int(way) == 1 :
 
 -     for n in range(1,33):
 
 -         if len(red) <= 29:
 
 -             n = random.randint(1,32)
 
 -             if n in red:
 
 -                 continue
 
 -             red.append(n)
 
 -         if len(blue) <=4:
 
 -             m = random.randint(1,16)
 
 -             if m in blue:
 
 -                 continue
 
 -             blue.append(m)
 
 -     print('这次的幸运号分别是是:','第一注红球'red.[0:5],'第一注蓝球',blue.[0],/n)
 
 -     print('                      ','第二注红球'red.[6:11],'第二注蓝球',blue.[1],/n)
 
 -     print('                      ','第三注红球'red.[12:16],'第三注蓝球',blue.[2],/n)
 
 -     print('                      ','第四注红球'red.[17:21],'第四注蓝球',blue.[3],/n)
 
 -     print('                      ','第五注红球'red.[22:27],'第五注蓝球',blue.[4],/n)
 
 - elif int(way) == 2 :
 
 -     for n in range(1,34):
 
 -         if len(red) <= 19:
 
 -             n = random.randint(1,34)
 
 -             if n in red:
 
 -                 continue
 
 -             red.append(n)
 
 -         if len(blue) <=9:
 
 -             m = random.randint(1,12)
 
 -             if m in blue:
 
 -                 continue
 
 -             blue.append(m)
 
 -     print('这次的幸运号分别是是:','第一注红球'red.[0:4],'第一注蓝球',blue.[0:1],/n)
 
 -     print('                      ','第二注红球'red.[5:9],'第二注蓝球',blue.[2:3],/n)
 
 -     print('                      ','第三注红球'red.[10:14],'第三注蓝球',blue.[4:5],/n)
 
 -     print('                      ','第四注红球'red.[15:19],'第四注蓝球',blue.[6:7],/n)
 
 -     print('                      ','第五注红球'red.[20:24],'第五注蓝球',blue.[8:9],/n)
 
  
- else:
 
 -     print('老板请不要开玩笑。')
 
 - input('按回车结束程序: ')
 
 
  复制代码 
 
感谢!
 本帖最后由 Twilight6 于 2020-6-10 22:20 编辑 
问题蛮多的: 
 
 
-  way 已经在 input 转为 int 了,不用再次 int
 
 -  这个地方的red前面需要有个逗号,red 后面 不能加了个 '.' ,还有后面的 /n 需要写成字符串,因为/n是字符串转义字符,表换行作用
 
 
- print('这次的幸运号分别是是:','第一注红球'red.[0:5],'第一注蓝球',blue.[0],/n)
 
  复制代码 
 
改成: 
 
-     print('这次的幸运号分别是是:','第一注红球',red[0:5],'第一注蓝球',blue[0],'/n')
 
  复制代码 
 
这样这里就不会报错了 
 -  列表切片用法错误,你red[0:5] 是取了 red 列表里的 0~4个元素了
 
 -  问题有点小多....很多用法都错了
 
 
  
 
帮你纠正了下语法错误的代码,可以正常运行了,你自己想想办法达到你自己的目的吧: 
 
- #买彩票
 
 - import random
 
 - import math
 
 - red = []
 
 - blue = []
 
 - print('请问老板是玩双色球还是大乐透?')
 
 - print('双色球请输入1,大乐透请输入2。')
 
 - way = int(input('请输入您的选择: '))
 
  
- if way == 1 :
 
 -     for n in range(1,33):
 
 -         if len(red) <= 29:
 
 -             n = random.randint(1,32)
 
 -             if n in red:
 
 -                 continue
 
 -             red.append(n)
 
 -         if len(blue) <=4:
 
 -             m = random.randint(1,16)
 
 -             if m in blue:
 
 -                 continue
 
 -             blue.append(m)
 
 -     print('这次的幸运号分别是是:','第一注红球',red[0:5],'第一注蓝球',blue[0],'/n')
 
 -     print('                      ','第二注红球',red[6:11],'第二注蓝球',blue[1],'/n')
 
 -     print('                      ','第三注红球',red[12:16],'第三注蓝球',blue[2],'/n')
 
 -     print('                      ','第四注红球',red[17:21],'第四注蓝球',blue[3],'/n')
 
 -     print('                      ','第五注红球',red[22:27],'第五注蓝球',blue[4],'/n')
 
 - elif way == 2 :
 
 -     for n in range(1,34):
 
 -         if len(red) <= 19:
 
 -             n = random.randint(1,34)
 
 -             if n in red:
 
 -                 continue
 
 -             red.append(n)
 
 -         if len(blue) <=9:
 
 -             m = random.randint(1,12)
 
 -             if m in blue:
 
 -                 continue
 
 -             blue.append(m)
 
 -     print('这次的幸运号分别是是:','第一注红球',red[0:4],'第一注蓝球',blue[0:1],'/n')
 
 -     print('                      ','第二注红球',red[5:9],'第二注蓝球',blue[2:3],'/n')
 
 -     print('                      ','第三注红球',red[10:14],'第三注蓝球',blue[4:5],'/n')
 
 -     print('                      ','第四注红球',red[15:19],'第四注蓝球',blue[6:7],'/n')
 
 -     print('                      ','第五注红球',red[20:24],'第五注蓝球',blue[8:9],'/n')
 
  
- else:
 
 -     print('老板请不要开玩笑。')
 
 - input('按回车结束程序: ')
 
 
  复制代码 
 
 
 
 |   
 
 
 
 |