Tulis kode untuk mengetahui apakah tahun tertentu adalah tahun kabisat atau bukan dengan python

Alat berikut memvisualisasikan apa yang dilakukan komputer langkah demi langkah saat menjalankan program tersebut

Editor Kode Python

Kontribusikan kode dan komentar Anda melalui Disqus

Sebelumnya. Tulis skrip Python untuk menampilkan berbagai format Tanggal Waktu
Lanjut. Tulis program Python untuk mengubah string menjadi datetime

Berapa tingkat kesulitan latihan ini?

Mudah Sedang Keras

Uji keterampilan Pemrograman Anda dengan kuis w3resource



Ikuti kami di Facebook dan Twitter untuk pembaruan terkini.

Piton. Kiat Hari Ini

Kelas Enum

Ini adalah pendekatan berkelas lain dari Python, tidak ada permainan kata-kata. Kelas enum Python akan memungkinkan Anda membuat anggota objek enum dengan nilai konstan dan unik yang kemudian dapat dicantumkan, dibandingkan, atau digunakan untuk identifikasi

Ini adalah panduan untuk Program Tahun Kabisat dengan Python. Di sini kita membahas contoh teratas Program Tahun Kabisat dengan Python dan implementasi kodenya. Anda juga dapat membaca artikel terkait lainnya untuk mempelajari lebih lanjut –

Leap Year
6
1
1
1
2

1
3
1
4
1
5
1
6

 

Leap Year
6
1
8

Leap Year
6
Leap Year
0

Leap Year
6
1
1
Leap Year
3

1
3
1
4
Leap Year
6
1
6

 

Leap Year
6
Leap Year
9

Leap Year
6
Leap Year
9

Leap Year
6
1
1
Leap Year
4

1
3
1
4
1
5
1
6

Leap Year
6
1
4
Leap Year
6
1
6

// C++ program to check if a given_3

 

// C++ program to check if a given_4

Leap Year
3 // C++ program to check if a given6

Leap Year
5

Leap Year
6
Leap Year
3 // year is leap year or not0

 

Leap Year
6// year is leap year or not2// year is leap year or not3// year is leap year or not4

// year is leap year or not5// year is leap year or not6// year is leap year or not7

1
6

Leap Year
6
1
4 #include <bits/stdc++.h>1

// C++ program to check if a given_3

 

#include <bits/stdc++.h>_3

#include <bits/stdc++.h>_4

C




#include <bits/stdc++.h>_5

// year is leap year or not

#include <bits/stdc++.h>_7

#include <bits/stdc++.h>_8

 

Leap Year
1
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
5

Leap Year
6
Leap Year
7

Leap Year
6
Leap Year
9

Leap Year
6
1
1
1
2

1
3
1
4
1
5
1
6

 

Leap Year
6
1
8

Leap Year
6
Leap Year
0

Leap Year
6
1
1
Leap Year
3

1
3
1
4
Leap Year
6
1
6

 

Leap Year
6
Leap Year
9

Leap Year
6
Leap Year
9

Leap Year
6
1
1
Leap Year
4

1
3
1
4
1
5
1
6

Leap Year
6
1
4
Leap Year
6
1
6

// C++ program to check if a given_3

 

Leap Year
_22

Leap Year
3 // C++ program to check if a given6

Leap Year
5

Leap Year
6
Leap Year
3 // year is leap year or not0

 

Leap Year
6
Leap Year
30
Leap Year
31
Leap Year
32// year is leap year or not3
Leap Year
34

Leap Year
35
Leap Year
31
Leap Year
32// year is leap year or not7
Leap Year
39

Leap Year
6
1
4 #include <bits/stdc++.h>1

// C++ program to check if a given_3

Jawa




Leap Year
_44

Leap Year
_45

Leap Year
_6

Leap Year
47
Leap Year
48

Leap Year
5

Leap Year
6
Leap Year
51
Leap Year
52
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
6
Leap Year
5

1
3
Leap Year
7

1
_3
Leap Year
9

1
3
1
1
Leap Year
64
Leap Year
65
Leap Year
66
Leap Year
67
Leap Year
68

Leap Year
69
1
4
1
5
1
6

Leap Year
_6

1
_3
1
8

1
_3
Leap Year
0

1
3
1
1
Leap Year
64
Leap Year
81
Leap Year
66
Leap Year
67
Leap Year
68

Leap Year
69
1
4
Leap Year
6
1
6

Leap Year
_6

1
_3
Leap Year
9

1
_3
Leap Year
9

1
3
1
1
Leap Year
64
Leap Year
97
Leap Year
66
Leap Year
67
Leap Year
68

Leap Year
69
1
4
1
5
1
6

1
3
1
4
Leap Year
6
1
6

Leap Year
6// C++ program to check if a given3

1
_3

Leap Year
6
1
13

Leap Year
6
1
15
Leap Year
51
1
17
1
18

Leap Year
6
Leap Year
5

1
3
Leap Year
3
1
23
1
24
1
6

1
3
1
27
1
24
1
29// year is leap year or not3 // year is leap year or not4

1
_32// year is leap year or not7
Leap Year
39

Leap Year
6// C++ program to check if a given3

// C++ program to check if a given_3

Python3




1
_38

1
_39
1
40

Leap Year
6
1
1
1
43
1
44
Leap Year
97
Leap Year
68
1
47
1
47
Leap Year
67________903______4

1
3
1
1
1
43
1
44
Leap Year
81
Leap Year
68
1
47
1
47
Leap Year
67________903______4

Leap Year
69
1
1
1
43
1
44
Leap Year
65
Leap Year
68
1
47
1
47
Leap Year
67________903______4

1
_71
1
4
1
73

Leap Year
69
1
75// year is leap year or not4

1
_71
1
4
1
79

1
_3
1
75// year is leap year or not4

1
_83
1
4
1
73

Leap Year
6
1
75// year is leap year or not4

1
3
1
4
1
79

 

1
_92

1
_93
1
47
1
24

1
1
1
97

Leap Year
6
1
99
Leap Year
32// year is leap year or not3
Leap Year
68

1
75// year is leap year or not4

Leap Year
6
1
99
Leap Year
32// year is leap year or not7
Leap Year
68

Leap Year
_6

Leap Year
_11

C#




Leap Year
_12

Leap Year
_45

using

Leap Year
15

 

Leap Year
47
Leap Year
17

Leap Year
5

Leap Year
_6

Leap Year
6
Leap Year
51
Leap Year
1
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
6
Leap Year
5

1
3
Leap Year
7

1
_3
Leap Year
9

1
3
1
1
1
2

Leap Year
69
1
4
1
5
1
6

Leap Year
_6

1
_3
1
8

1
_3
Leap Year
0

1
3
1
1
Leap Year
3

Leap Year
69
1
4
Leap Year
6
1
6

Leap Year
_6

1
_3
Leap Year
9

1
_3
Leap Year
9

1
3
1
1
Leap Year
4

Leap Year
69
1
4
1
5
1
6

1
3
1
4
Leap Year
6
1
6

Leap Year
6// C++ program to check if a given3

1
_3

Leap Year
6
1
13

Leap Year
6
1
15
Leap Year
51
1
17
Leap Year
76

Leap Year
6
Leap Year
5

1
3
Leap Year
3 // year is leap year or not0

1
3
Leap Year
83// year is leap year or not3 // year is leap year or not4

Leap Year
86// year is leap year or not7
Leap Year
39

Leap Year
6// C++ program to check if a given3

 

// C++ program to check if a given_3

 

Leap Year
_92

PHP




Leap Year
_93

Leap Year
_94

Leap Year
_95

 

Leap Year
_96
Leap Year
2
Leap Year
98
Leap Year
68

Leap Year
5

Leap Year
6
Leap Year
7

Leap Year
6
Leap Year
9

Leap Year
6
1
1
Leap Year
32
Leap Year
98
Leap Year
09

1
3
1
99
Leap Year
32// year is leap year or not3
Leap Year
39

1
_3

Leap Year
6
1
8

Leap Year
6
Leap Year
0

Leap Year
6
1
75
1
1
Leap Year
32
Leap Year
98
Leap Year
25

1
3
1
99
Leap Year
32// year is leap year or not7________0______39

Leap Year
_69

Leap Year
6
Leap Year
9

Leap Year
6
Leap Year
9

Leap Year
6
1
75
1
1
Leap Year
32
Leap Year
98
Leap Year
41

1
3
1
99
Leap Year
32// year is leap year or not3
Leap Year
39

1
_3

Leap Year
6
1
75

1
3
1
99
Leap Year
32// year is leap year or not7________0______39

// C++ program to check if a given_3

 

// C++ program to check if a given_4

Leap Year
_98
Leap Year
58

 

Leap Year
2
Leap Year
98
Leap Year
39

Leap Year
_6

Leap Year
_63

Leap Year
_64

Javascript




Leap Year
_65

 

Leap Year
_66

Leap Year
_45

 

Leap Year
6
Leap Year
96
Leap Year
70

1
3
Leap Year
7

1
_3
Leap Year
9

1
3
1
1
1
2

Leap Year
69
1
4
1
5
1
6

 

1
_3
1
8

1
_3
Leap Year
0

1
3
1
1
Leap Year
3

Leap Year
69
1
4
Leap Year
6
1
6

 

1
_3
Leap Year
9

1
_3
Leap Year
9

1
3
1
1
Leap Year
4

Leap Year
69
1
4
1
5
1
6

1
3
1
4
Leap Year
6
1
6

Leap Year
6// C++ program to check if a given3

 

Leap Year
6
1
13

// C++ program to check if a given_12

1
_3// C++ program to check if a given14

1
3// C++ program to check if a given16// year is leap year or not3 // year is leap year or not4// year is leap year or not7
Leap Year
39

 

 

// C++ program to check if a given_21

 

// C++ program to check if a given_22

Keluaran

Leap Year

Kompleksitas Waktu. O(1)

Ruang Bantu. O(1)

Contoh 2. Kode satu baris untuk memeriksa apakah tahun itu adalah tahun kabisat atau bukan

C++




// C++ program to check if a given_23

// C++ program to check if a given_24

#include <bits/stdc++.h>

using namespace

Leap Year
0

 

Leap Year
1
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
5

Leap Year
_6

Leap Year
6// C++ program to check if a given36

Leap Year
6// C++ program to check if a given38

Leap Year
6// C++ program to check if a given40

Leap Year
6
1
4 // C++ program to check if a given43

1
_83// C++ program to check if a given45

// C++ program to check if a given_3

 

// C++ program to check if a given_4

Leap Year
3 // C++ program to check if a given6

Leap Year
5

Leap Year
6
Leap Year
3 // year is leap year or not0

 

Leap Year
6// C++ program to check if a given55// year is leap year or not3// year is leap year or not4

// C++ program to check if a given58// year is leap year or not6// year is leap year or not7

1
6

Leap Year
6
1
4 #include <bits/stdc++.h>1

// C++ program to check if a given_3

 

// C++ program to check if a given_66

C




// C++ program to check if a given_23

// C++ program to check if a given_24

#include <bits/stdc++.h>_7

#include <bits/stdc++.h>_8

 

Leap Year
1
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
5

// C++ program to check if a given_36

// C++ program to check if a given_77

// C++ program to check if a given_40

1
4 // C++ program to check if a given43

1
_3// C++ program to check if a given45

// C++ program to check if a given_3

 

Leap Year
_22

Leap Year
3 // C++ program to check if a given6

Leap Year
5

Leap Year
6
Leap Year
3 // year is leap year or not0

 

Leap Year
6
Leap Year
30
Leap Year
31
Leap Year
32// year is leap year or not3
Leap Year
34

1
71
Leap Year
31
Leap Year
32// year is leap year or not7
Leap Year
39

Leap Year
6
1
4 #include <bits/stdc++.h>1

// C++ program to check if a given_3

Jawa




Leap Year
_44

Leap Year
_45

Leap Year
_6

Leap Year
47
Leap Year
48

Leap Year
5

Leap Year
6
Leap Year
51
Leap Year
52
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
6
Leap Year
5

Leap Year
6// C++ program to check if a given36

Leap Year
6// C++ program to check if a given38

Leap Year
6// C++ program to check if a given40

Leap Year
6
1
4 // year is leap year or not28
Leap Year
97
Leap Year
66
Leap Year
67// year is leap year or not32
Leap Year
81 // year is leap year or not34
Leap Year
67________903_____903_____

Leap Year
69
Leap Year
64
Leap Year
65
Leap Year
66
Leap Year
67// year is leap year or not42

Leap Year
6// C++ program to check if a given3

1
_3

Leap Year
6
1
13

Leap Year
6
1
15
Leap Year
51
1
17
1
18

Leap Year
6
Leap Year
5

1
3
Leap Year
3
1
23
1
24
1
6

1
3// year is leap year or not61
1
24
1
29// year is leap year or not3 // year is leap year or not4

1
_32// year is leap year or not7
Leap Year
39

Leap Year
6// C++ program to check if a given3

// C++ program to check if a given_3

Python3




// year is leap year or not_72

// year is leap year or not_73

 

1
_39
1
40

 

Leap Year
6// year is leap year or not77

Leap Year
6// year is leap year or not79

Leap Year
6// year is leap year or not81

Leap Year
6
1
4 // year is leap year or not84
1
44
Leap Year
97
1
47
1
47
Leap Year
67
Leap Year
68// year is leap year or not91
1
43
1
44
Leap Year
81 // year is leap year or not95
1
47
Leap Year
67// year is leap year or not98// year is leap year or not99
1
43
1
44
Leap Year
65
1
47
1
47
Leap Year
67// year is leap year or not42

 

1
_92

1
_93
1
47
1
24

1
1
1
97

Leap Year
6
1
99
Leap Year
32// year is leap year or not3
Leap Year
68

1
75// year is leap year or not4

Leap Year
6
1
99
Leap Year
32// year is leap year or not7
Leap Year
68

Leap Year
_6

Leap Year
_11

C#




Leap Year
_12

Leap Year
_45

using

Leap Year
15

 

Leap Year
47
Leap Year
17

Leap Year
5

Leap Year
6
Leap Year
51
Leap Year
1
Leap Year
2
Leap Year
3
Leap Year
4

Leap Year
6
Leap Year
5

1
_3// C++ program to check if a given36

1
_3// C++ program to check if a given38

1
_3// C++ program to check if a given40

1
_3
1
4 // C++ program to check if a given43

1
71// C++ program to check if a given45

Leap Year
6// C++ program to check if a given3

1
_3

Leap Year
6
1
13

Leap Year
6
1
15
Leap Year
51
1
17
Leap Year
76

Leap Year
6
Leap Year
5

1
3
Leap Year
3 // year is leap year or not0

1
3
Leap Year
83// year is leap year or not3 // year is leap year or not4

Leap Year
86// year is leap year or not7
Leap Year
39

Leap Year
6// C++ program to check if a given3

 

// C++ program to check if a given_3

Leap Year
_92

PHP




Leap Year
_93

Leap Year
_94

Leap Year
_95

 

Leap Year
_96
Leap Year
2
Leap Year
98
Leap Year
68

Leap Year
5

Leap Year
_6

Leap Year
6// C++ program to check if a given36

Leap Year
6// C++ program to check if a given38

Leap Year
6// C++ program to check if a given40

Leap Year
6
1
4 #include <bits/stdc++.h>96
Leap Year
98 #include <bits/stdc++.h>98

1
83
Leap Year
32
Leap Year
98 using02

1
83
Leap Year
32
Leap Year
98 using06

// C++ program to check if a given_3

 

// C++ program to check if a given_4

Leap Year
_98
Leap Year
58

 

Leap Year
2
Leap Year
98
1
29
1
99
Leap Year
32// year is leap year or not3
Leap Year
34

using18

1
99
Leap Year
32// year is leap year or not7
Leap Year
39

 

Leap Year
_63

Leap Year
_64

Javascript




Leap Year
_65

using_26

Leap Year
_45

Leap Year
6
Leap Year
96 using30

Leap Year
6
Leap Year
5

Leap Year
_6

1
_3// C++ program to check if a given36

1
_3// C++ program to check if a given38

1
_3// C++ program to check if a given40

1
_3
1
4 using42

Leap Year
6// C++ program to check if a given3

 

Leap Year
6
1
13

Leap Year
6using48 // year is leap year or not0

Leap Year
6// C++ program to check if a given16// year is leap year or not3 // year is leap year or not4// year is leap year or not7
Leap Year
39

 

 

using_56

// C++ program to check if a given_22

Keluaran

Leap Year

Kompleksitas Waktu. O(1)

Ruang Bantu. O(1)

Contoh 3. Periksa Tahun Kabisat menggunakan Macro di C/C++

C++




using_58

using_59

using_60

 

using_61

using namespace

Leap Year
0

 

using_65

using_66

using_67

using_68

using_69

using_70

Leap Year
3 // C++ program to check if a given6

Leap Year
5

Leap Year
6
Leap Year
3 using76

Leap Year
6using78using79
1
6

Leap Year
6
1
4 #include <bits/stdc++.h>1

// C++ program to check if a given_3

Jawa




using_85

using_59

using_60

1
_15
Leap Year
47 using90

Leap Year
5

________940

Leap Year
_940_______65

________940

Leap Year
_940_______66

using92

Leap Year
51
Leap Year
3 using99
Leap Year
3 namespace01

using_92

Leap Year
5

Leap Year
6
1
1namespace06
Leap Year
65
Leap Year
66
Leap Year
67namespace10

using69namespace12

Leap Year
81 // year is leap year or not34
Leap Year
67namespace16

using69namespace12

Leap Year
97
Leap Year
66
Leap Year
67// year is leap year or not98

Leap Year
6
Leap Year
5

namespace25

1
4 namespace27
1
6

Leap Year
6// C++ program to check if a given3

Leap Year
6
1
75

Leap Year
6
Leap Year
5

namespace25

1
4
Leap Year
67
1
6

Leap Year
6// C++ program to check if a given3

________940

Leap Year
_900_______3

 

________940

Leap Year
_900_______4

using92

1
15
Leap Year
51
1
17 ________1______18

using_92

Leap Year
5

Leap Year
6
Leap Year
3
1
23namespace55
1
6

Leap Year
6namespace58

________940

Leap Year
_900_______3

// C++ program to check if a given_3

 

namespace_62

Python3




namespace_63

namespace_64

namespace_65

 

namespace_66

namespace_67

1
_39 namespace69

using92

1
1namespace72
1
44 ________0______65
1
47
1
47
Leap Year
67
Leap Year
68________903______99

// C++ program to check if a given12namespace81

1
44
Leap Year
81 // year is leap year or not95
1
47
Leap Year
67
Leap Year
68// year is leap year or not91

// C++ program to check if a given12namespace81

1
44
Leap Year
97
1
47
1
47
Leap Year
67namespace96

Leap Year
6
1
4 namespace27
1
6

using_92

1
75// year is leap year or not4

Leap Year
6
1
4
Leap Year
67
1
6

 

Leap Year
_008

1
1
Leap Year
010
1
47
1
47
Leap Year
013// year is leap year or not4

 

using92

1
93
1
47 namespace55
1
6

using_92

1
99
Leap Year
022

 

using_92

Leap Year
024

C#




Leap Year
_025

using_59

using_60

using

Leap Year
15

Leap Year
47
Leap Year
031

Leap Year
_6

________940

Leap Year
_940_______65

________940

Leap Year
_940_______66

using92

Leap Year
51
Leap Year
3 using99
Leap Year
3 namespace01

using_92

Leap Year
5

Leap Year
6
1
1
Leap Year
047

using_69

Leap Year
049

using_69

Leap Year
051

Leap Year
6
Leap Year
5

namespace_25

1
4
Leap Year
056

Leap Year
6// C++ program to check if a given3

Leap Year
6
1
75

Leap Year
6
Leap Year
5

namespace_25

1
4 #include <bits/stdc++.h>1

Leap Year
6// C++ program to check if a given3

________940

Leap Year
_900_______3

using_92

________940

Leap Year
_900_______4

using_92

Leap Year
51
1
17
Leap Year
76

using_92

Leap Year
5

Leap Year
6
Leap Year
3 using76

Leap Year
6
Leap Year
083

________940

Leap Year
_900_______3

// C++ program to check if a given_3

 

Leap Year
_087

Javascript




Leap Year
_65

Leap Year
_089

using_59

using_60

 

________940

Leap Year
_940_______65

________940

Leap Year
_940_______66

using_92

Leap Year
96
Leap Year
098

using_92

Leap Year
5

Leap Year
6
1
1
Leap Year
047

using_69

Leap Year
049

using_69

Leap Year
051

Leap Year
6
Leap Year
5

namespace_25

1
4
Leap Year
056

Leap Year
6// C++ program to check if a given3

Leap Year
6
1
75

Leap Year
6
Leap Year
5

namespace_25

1
4 #include <bits/stdc++.h>1

Leap Year
6// C++ program to check if a given3

________940

Leap Year
_900_______3

 

________940

Leap Year
_900_______4

________940

Leap Year
_940_______48 using76

using_92

Leap Year
132

using_92

Leap Year
_134

// C++ program to check if a given_22

Keluaran

1
_

Kompleksitas Waktu. O(1)

Ruang Bantu. O(1)

Penjelasan

Program mengeluarkan 1 jika tahun itu adalah kabisat dan 0 jika itu bukan tahun kabisat

Contoh 4. Solusi Singkat dengan Python

Piton




1
_39
1
40

Leap Year
_138

Leap Year
6// year is leap year or not77

Leap Year
6// year is leap year or not79

Leap Year
6// year is leap year or not81

Leap Year
6
Leap Year
146
Leap Year
147

Leap Year
6
1
4
Leap Year
150

Leap Year
_138

Leap Year
_152

1
_93
1
47
1
24

1
1
1
97

Leap Year
6
1
99
Leap Year
32// year is leap year or not3
Leap Year
68

1
75// year is leap year or not4

Leap Year
6
1
99
Leap Year
32// year is leap year or not7
Leap Year
68

using_69

Leap Year
_171

Keluaran

Leap Year

Kompleksitas Waktu. O(1)

Ruang Bantu. O(1)

Contoh 5. Solusi Singkat di Java menggunakan metode isLeap() dari kelas Tahun

Jawa




Leap Year
_172

Leap Year
_173

 

Leap Year
146
Leap Year
175

Leap Year
146
Leap Year
177

 

Leap Year
47
Leap Year
031

Leap Year
_6

Leap Year
6
Leap Year
182

Leap Year
6
1
15
Leap Year
51
Leap Year
52
Leap Year
2
Leap Year
3
Leap Year
189

1
3
Leap Year
191
Leap Year
192

1
3
1
4
Leap Year
195

Leap Year
6// C++ program to check if a given3

Leap Year
_6

Leap Year
6
Leap Year
200

Leap Year
6
1
15
Leap Year
51
1
17
Leap Year
205

1
3
Leap Year
3
1
23
1
24
1
6
Leap Year
211

1
3
1
1
Leap Year
214
Leap Year
215

Leap Year
69
Leap Year
217// year is leap year or not3
Leap Year
39

1
3// C++ program to check if a given3
1
75
Leap Year
5

Leap Year
69
Leap Year
217// year is leap year or not7
Leap Year
39

1
_3// C++ program to check if a given3

Leap Year
6// C++ program to check if a given3

// C++ program to check if a given_3

 

Leap Year
_233

Keluaran

Leap Year

Kompleksitas Waktu. O(1)

Ruang Bantu. O(1)

Penjelasan

Kelas tahun di java adalah kelas built-in yang digunakan untuk merepresentasikan tahun sebagai objek tetap tanggal-waktu. Idenya adalah untuk memanggil metode isLeap() dari kelas yang mengembalikan true jika tahun adalah tahun kabisat dan sebaliknya

Bagaimana Anda menemukan tahun adalah kode tahun kabisat?

Tahun kabisat habis dibagi 4 kecuali tahun abad (tahun diakhiri dengan 00). Tahun abad adalah tahun kabisat hanya jika habis dibagi 400. .
Tahun 1999 bukanlah tahun kabisat
Tahun 2000 adalah tahun kabisat
Tahun 2004 adalah tahun kabisat

Bagaimana Anda memeriksa 2100 adalah tahun kabisat atau bukan?

Jika habis dibagi 100, tahun Gregorian adalah tahun normal dengan 365 hari (e. g. 1900/100=19, jadi 1900 adalah tahun normal dengan 365 hari; . Jika habis dibagi 400, tahun Gregorian adalah tahun kabisat ; .