弹珠游戏?
import random
# method1
light = ''
for i in range(12):
light = light + str(random.randint(0,1))
else:
# 1表示亮灯,0表示没亮
print("亮灯情况",light)
location = random.randint(1,12)
print("你打到了第%s个灯"%location)
if light[location-1] == '1':
print("恭喜你打中了!")
else:
print("很遗憾你没有打中")
模拟千分位
number = input("请输入一串数字:")
count = 0 # 标注这串数字的第几位
result = '' # 用来存储分割好的字符串
if number.isdigit():
for i in number[::-1]:
count += 1
result = i + result
if count % 3 == 0 and count != len(number):
result = ',' + result
else:
print('千分位格式为:', result)
else:
print("亲,您的输入不合法,请输入数字哦")
# method2:数字正向
str_number = input("请输入一串数字")
# method3
num = input("请输入一串数字")
turn_num = ""
length = len(num)
i = length -3
|