|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 无理想的闲鱼 于 2022-10-20 15:46 编辑
网课抽同学回答问题
- import random
- #list1 = []
- count1 = 0
- count2 = 0
- count3 = 0
- count4 = 0
- i= int(input("请输入你要抽的人数:"))
- while i > 0:
- temp=["鸡蛋","鸭蛋","鹅蛋","鸟蛋"]
- x = random.choice(temp)
- print(x)
- if x == "鸡蛋":
- count1 += 1
- if x == "鸭蛋":
- count2 += 1
- if x == "鹅蛋":
- count3 += 1
- if x == "鸟蛋":
- count4 += 1
- #list1.append(x)
- i -= 1
- #list1.sort()
- #print(list1)
- print("抽中鸡蛋的次数是",count1,sep="")
- print("抽中鸭蛋的次数是",count2,sep="")
- print("抽中鹅蛋的次数是",count3,sep="")
- print("抽中鸟蛋的次数是",count4,sep="")
复制代码
|
-
程序实现如下
|