Thamizhiniyan C S
HomeWriteupsResourcesCheatsheets
HackerRank
HackerRank
  • HackerRank
  • Linux Shell
    • Bash
    • Text Processing
      • Cut
      • Head
      • Middle
      • Tail
      • Tr
      • Sort
      • Uniq
      • Paste
    • Arrays In Bash
    • Grep Sed Awk
      • Grep
      • Sed
      • Awk
  • Regex
    • Introduction
    • Character Class
    • Repetitions
    • Grouping and Capturing
    • Backreferences
    • Assertions
    • Applications
  • Python
    • Introduction
    • Basic Data Types
    • Strings
    • Sets
    • Math
    • Itertools
    • Collections
    • Date and Time
    • Errors and Exceptions
    • Classes
    • Built-Ins
    • Python Functionals
    • Regex and Parsing
    • XML
    • Closures and Decorators
    • Numpy
    • Debugging
  • C
    • Introduction
    • Conditionals and Loops
    • Arrays and Strings
Powered by GitBook
On this page
  • Say "Hello, World!" With Python
  • Python If-Else
  • Arithmetic Operators
  • Python: Division
  • Loops
  • Write a Function
  • Print Function

Was this helpful?

  1. Python

Introduction

PreviousPythonNextBasic Data Types

Last updated 9 months ago

Was this helpful?

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))

Print Function

if __name__ == '__main__':
    n = int(input())
    for i in range(1, n + 1):
        print(i, end="")
Solve Programming Questions | HackerRankHackerRank
Logo