Given an integer, , perform the following conditional actions:
If is odd, print Weird If is even and in the inclusive range of to , print Not Weird If is even and in the inclusive range of to , print Weird If is even and greater than , print Not Weird Input Format
A single line containing a positive integer, .
Constraints: 1<=n<=100
Output Format
Print Weird if the number is weird; otherwise, print Not Weird.
Sample Input 0
3 Sample Output 0
Weird Sample Input 1
24 Sample Output 1
Not Weird Explanation
Sample Case 0:
is odd and odd numbers are weird, so we print Weird.
Sample Case 1:
n>20 and n is even, so it isn't weird. Thus, we print Not Weird.
In [1]:
if __name__ == '__main__':
n = int(input())
if 1 <= n <= 100:
if n%2 ==0:
if n > 20 or 2<=n<=5:
print ("Not Weird")
else:
print ("Weird")
else:
print ("Weird")
Read two integers from STDIN and print three lines where:
The first line contains the sum of the two numbers. The second line contains the difference of the two numbers (first - second). The third line contains the product of the two numbers. Input Format
The first line contains the first integer, . The second line contains the second integer, .
Constraints
1<=a<=10e10 and 1<=b<=10e10
Output Format
Print the three lines as explained above.
Sample Input
3 2 Sample Output
5 1 6
In [2]:
if __name__ == '__main__':
a = int(input())
b = int(input())
if 1<=a<=10e10 and 1<=b<=10e10:
print (a+b)
print (a-b)
print (a*b)
Read two integers and print two lines. The first line should contain integer division, // . The second line should contain float division, / .
You don't need to perform any rounding or formatting operations.
Input Format The first line contains the first integer, . The second line contains the second integer, .
Output Format Print the two lines as described above.
Sample Input
4 3 sample Output
1 1.3333333333333333
In [3]:
if __name__ == '__main__':
a = int(input())
b = int(input())
print (int(a//b))
print (float(a/b))
In [4]:
if __name__ == '__main__':
n = int(input())
if 1<=n<=20:
for i in range(0,n):
print (i*i)
We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary day and we add it to the shortest month of the year, February. In the Gregorian calendar three criteria must be taken into account to identify leap years:
The year can be evenly divided by 4, is a leap year, unless: The year can be evenly divided by 100, it is NOT a leap year, unless: The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.Source
Task You are given the year, and you have to write a function to check if the year is leap or not.
Note that you have to complete the function and remaining code is given as template.
Input Format
Read y, the year that needs to be checked.
Constraints
1900 <= y <= 10e5
Output Format
Output is taken care of by the template. Your function must return a boolean value (True/False)
Sample Input
1990
Sample Output
False
Explanation
1990 is not a multiple of 4 hence it's not a leap year.
In [5]:
def is_leap(year):
if 1900<= year <= 10e5:
if year%4==0:
if year%100==0 and year%400==0:
leap = True
else:
if year%100==0:
leap = False
else:
leap = True
else:
leap = False
return bool(leap)
In [6]:
year = int(input())
print(is_leap(year))
In [7]:
if __name__ == '__main__':
n = int(input())
for i in range(1, n+1):
print(i, end='')
In [ ]: