-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerRank Easy Python Problems
More file actions
57 lines (43 loc) · 1.61 KB
/
HackerRank Easy Python Problems
File metadata and controls
57 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Challenge: Say "Hello, World!" With Python
# print("Hello, World!")
print("Hello, World!")
# Challenge: Arithmetic Operators
# The provided code stub reads two integers from STDIN, a and b.
# Add code to print three lines where:
# 1. The first line contains the sum of the two numbers.
# 2. The second line contains the difference of the first two numbers (first minus second).
# 3. The third line contains the product of the two numbers.
print(a + b)
print(a - b)
print(a * b)
# Challenge: Python: Division
# The provided code stub reads two integers, a and b, from STDIN.
# Add logic to print two lines. The first line should contain the result of integer division, a // b.
# The second line should contain the result of float division, a / b.
print(a // b)
print(a / b)
# Challenge: Loops
# The provided code stub reads an integer, n, from STDIN.
# For all non-negative integers i < n, print i squared.
# Print n lines, one corresponding to each i.
if __name__ == '__main__':
n = int(input())
for i in range(n):
print(i * i)
# Challenge: Write a function
# Given a year, determine whether it is a leap year.
# If it is a leap year, return the Boolena True.
# Otherwise, return False.
def is_leap(year):
leap = ()
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
leap = True
else:
leap = False
return leap
year = int(input())
print(is_leap(year))
# Challenge: Print Function
# The included code stub will read an integer, n, from STDIN.
# Without using any string methods, try to print the following: 123...n
# Example: if n is 5, output should be 12345.