4、使用python验证码程序设计:随机生成4个0-9之间的整数,并打印。提示并输入4个整数,若与上述数字匹配,则显示验证码输入正确,否则提示验证码输入错误
时间: 2024-05-14 15:17:32 浏览: 50
以下是实现该功能的Python代码:
```python
import random
# 生成验证码
code = ''
for i in range(4):
code += str(random.randint(0, 9))
print('验证码为:', code)
# 输入验证码
input_code = input('请输入验证码:')
if input_code == code:
print('验证码输入正确')
else:
print('验证码输入错误')
```
运行结果示例:
```
验证码为: 8745
请输入验证码:1234
验证码输入错误
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)