Introduction

Say "Hello, World!" With Python

print("Hello, World!")

Python If-Else

if __name__ == "__main__":
    n = int(input().strip())
    if n % 2 != 0 or n % 2 == 0 and 6 <= n <= 20:
        print("Weird")
    elif n % 2 == 0 and 2 <= n <= 5 or n % 2 == 0 and n > 20:
        print("Not Weird")

Arithmetic Operators

if __name__ == '__main__':
    a = int(input())
    b = int(input())

    print(a + b)
    print(a - b)
    print(a * b)

Python: Division

if __name__ == '__main__':
    a = int(input())
    b = int(input())

    print(a // b)
    print(a / b)

Loops

if __name__ == '__main__':
    n = int(input())
    lst = list(range(0 , n))
    for each in lst:
        print(each * each)

Write a Function

def is_leap(year):
    if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
        return True
    else:
        return False


if __name__ == "__main__":
    year = 1992
    print(is_leap(year))

if __name__ == '__main__':
    n = int(input())
    for i in range(1, n + 1):
        print(i, end="")

Last updated