编写一个排列5的模拟摇奖程序
时间: 2024-02-20 18:59:55 浏览: 101
好的,我可以为您编写一个Python程序来模拟排列5的摇奖过程。以下是代码示例:
```python
import random
# 生成1-10之间的5个不同随机数
lottery = random.sample(range(1, 11), 5)
# 输出中奖号码
print("中奖号码为:", lottery)
```
该程序使用Python的random库生成1-10之间的5个不同的随机数,模拟排列5的摇奖过程。您可以多次运行程序,以模拟多次摇奖过程。
相关问题
排列五摇奖程序
好的,以下是一个简单的Python程序,用于模拟排列5的摇奖过程:
```python
import random
# 生成1到10之间的5个不同的数字
winning_numbers = random.sample(range(1, 11), 5)
# 输出中奖号码
print("中奖号码为:", winning_numbers)
# 模拟彩票购买过程,例如购买的彩票号码为[1, 2, 3, 4, 5]
my_numbers = [1, 2, 3, 4, 5]
# 比较购买的彩票号码和中奖号码
match_count = len(set(winning_numbers) & set(my_numbers))
# 判断中奖等级
if match_count == 5:
print("恭喜您中了一等奖!")
elif match_count == 4:
print("恭喜您中了二等奖!")
elif match_count == 3:
print("恭喜您中了三等奖!")
elif match_count == 2:
print("恭喜您中了四等奖!")
elif match_count == 1:
print("恭喜您中了五等奖!")
else:
print("很遗憾,您没有中奖。")
```
这个程序会生成5个1到10之间的不同数字作为中奖号码,然后比较我们购买的彩票号码和中奖号码,判断中奖等级。您可以多次运行程序,以模拟多次摇奖过程。
写一个html摇奖页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>摇奖页面</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f5f5f5;
}
#result {
font-size: 40px;
font-weight: bold;
margin-bottom: 50px;
color: #333;
}
button {
padding: 10px 20px;
font-size: 24px;
background-color: #008CBA;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>摇奖页面</h1>
<div id="result"></div>
<button id="btn">开始摇奖</button>
</div>
<script>
const prizes = ['一等奖', '二等奖', '三等奖', '谢谢参与'];
const result = document.querySelector('#result');
const btn = document.querySelector('#btn');
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
btn.addEventListener('click', () => {
const index = getRandomInt(prizes.length);
result.textContent = prizes[index];
});
</script>
</body>
</html>