判断输入的年份是否为闰年

#!/usr/bin/env python

import sys

def judge_year():
    while True:
	try:
	    year = raw_input(‘please input a year: ‘)
	except (EOFError,KeyboardInterrupt):
	    print ‘\n‘
	    sys.exit()
        if len(year) == 0:
	    print ‘input nothing,please try again!‘
	    continue
        try:
	    year = int(year)
        except ValueError,e:
	    print ‘please input 4 integers‘
	    continue
        if len(str(year)) != 4:
	    print ‘Number of digits should be 4‘
	    continue
        break

    if (year % 4 == 0) and (year % 100 != 0):
        print str(year)+‘ is a leap year‘
    elif (year % 4 == 0) and (year % 100 == 0):
        print str(year)+‘ is a leap year‘
    else:
        print ‘sorry! ‘+str(year)+‘ is not a leap year‘

def main():
    while True:
        judge_year()
	anwser = raw_input("Enter ‘no‘ to quit: ")
	if anwser == ‘no‘:
	    break
	else:
	    pass

if __name__ == ‘__main__‘:
    main()
时间: 2024-08-06 18:14:59

判断输入的年份是否为闰年的相关文章

计算输入的年份是否为闰年,并利用条件运算符输入“是”或者“不是”

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConditionOperator{ class Program { static void Main(string[] args) { Console.Write("请输入一个年份:");//屏幕输入提示字符串 string strYear = Console.ReadLine();//获取用户输入的年

判断给定的年份是否为闰年

#!/usr/bin/env python #coding:utf-8 def f(x):     if x%400 == 0 or x%4 == 0 and x%100 != 0:         print '%s 是闰年' % x     else:         print '%s 是平年' % x year = raw_input('Please a year number:') year = int(year) f(year)

判断年份是否为闰年及非法数据的处理

一.问题描述 判断输入的年份是否为闰年 二.功能实现 在输入栏中输入年份,点击确认按钮,若年份为闰年,则显示“您输入的年份是闰年”,如年份非闰年,则显示“您输入的年份不是闰年” 三.代码实现 <html> <head> <script type="text/javascript"> function test(){ var input1=document.getElementById('input1').value; if input1%400==0

判断输入年份是否为闰年的另一种方法

最近,我在网上看到了一道题目:输入一个从1901年开始到今年截止的年份,判断该年份是否为闰年? 对于这个题目,大家应该不会陌生,很多人在学校就应该已经见过了.通常的做法是判断输入的年份是否满足下列两个条件之一: 1) 能够被4整除但不能被100整除. 2) 能够被400整除. 如果满足两个条件中的任意一个,那么该年份就为闰年. 程序流程如下图所示: 程序代码如下: 现在,我们换一种思路来考虑.1901年开始到今年截止的年份中,闰年为1904.1908.1912等等,它们之间相差4年.这样,我们就

判断指定年份是否为闰年

原文:判断指定年份是否为闰年 判断指定年份是否为闰年,Insus.NET也曾经写过2篇<判断是否是闰年>https://www.cnblogs.com/insus/p/10865051.html和 <指定日期,判断其所属年份是否为闰年>https://www.cnblogs.com/insus/p/10841868.html SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ===========================

【VBA编程】03.判断输入年份是否是闰年

通过输入月份,判断是否是闰年 [代码区域] Sub 判断闰年() Dim year As Integer '用于保存输入的年份 year = CInt(InputBox("请输入需要判断的年份:", "判断闰年")) '输入年份 If year Mod 4 = 0 And year Mod 100 <> 0 Then MsgBox "" & "是一个闰年", vbOKOnly, "判断闰年&quo

输入一个年份,再输入一个月份,判断其是平年还是闰年,然后输出当前月份的天数。

#region 输入一个年份,再输入一个月份,判断其是平年还是闰年,然后输出当前月份的天数. Console.WriteLine("请输入一个年份"); int year = 0;//声明一个变量year,即年份 int month = 0;//声明一个变量month.即月份 int day = 0; //声明一个变量day,即天数 bool b = true;//声明一个变量b,即"是"或"否' //捕捉异常,判断用户输入的值是否合法 try { //当

作业3.输入一个年份,判断是闰年还是平年

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication1 7 { 8 class 闰平年 9 { 10 static void Main(string[] agre) 11 { 12 Console.Write("请输入一个年份:"); 13 string a = Console.ReadL

使用switch语句编程,根据输入的年份判断是否为闰年,根据输入的月份判断这月有多少天

#include <stdio.h> int main() { int year, month, flag = 0; printf("Enter Year And Month:!\n"); scanf("%d %d", &year, &month); if(year % 4 ==0 && year % 100 != 0 || year % 400 ==0) { flag = 1; printf("您所输入的年份是