根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century l eap year.”,如果为普通闰年输出“leap year.”,如果不为闰年输出“It i s not leap year.”。并设计测试数据进行判定覆盖测试
时间: 2024-05-21 12:10:22 浏览: 37
测试用例设计:
输入:2000
输出:Century leap year.
输入:2004
输出:leap year.
输入:1900
输出:It is not leap year.
输入:2001
输出:It is not leap year.
输入:0
输出:It is not leap year.
输入:-2000
输出:It is not leap year.
输入:2100
输出:It is not leap year.
输入:2020
输出:leap year.
输入:2024
输出:leap year.
输入:2400
输出:Century leap year.
相关问题
根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century l eap year.”,如果为普通闰年输出“leap year.”,如果不为闰年输出“It i s not leap year.”。并设计测试数据进行判定覆盖测试。
代码实现:
```python
year = int(input("请输入年份:"))
if year % 400 == 0:
print("Century leap year.")
elif year % 100 == 0:
print("It is not leap year.")
elif year % 4 == 0:
print("leap year.")
else:
print("It is not leap year.")
```
测试数据设计:
1. 输入2000,期望输出“Century leap year.”
2. 输入1900,期望输出“It is not leap year.”
3. 输入2020,期望输出“leap year.”
4. 输入2022,期望输出“It is not leap year.”
5. 输入1600,期望输出“Century leap year.”
根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century leap year.”如果为普通闰年输出“leap year.”如果不为闰年输出“It is not leap year.”并设计测试数据进行覆盖测试,使用Visio绘制程序框图。
判断闰年的方法如下:
1. 能被4整除但不能被100整除的年份是普通闰年。
2. 能被400整除的是世纪闰年。
下面是代码实现:
```
year = int(input("请输入一个年份:"))
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Century leap year.")
else:
print("It is not leap year.")
else:
print("leap year.")
else:
print("It is not leap year.")
```
测试数据:
| 输入 | 输出 |
| ---- | ---- |
| 2000 | Century leap year. |
| 2020 | leap year. |
| 1900 | It is not leap year. |
| 2001 | It is not leap year. |
Visio绘制的程序框图如下:
![程序框图](https://img-blog.csdnimg.cn/20210915104152396.png)
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)