Solutions
HackerRank
HackerRank
  • Home
  • 👨🏻‍💻 Profile
  • Prepare
    • Linux Shell
      • Bash
    • Python
      • Introduction
    • SQL
      • Basic Select
      • Advanced Select
      • Aggregation
      • Basic Join
  • Tutorials
    • 10 Days of Javascript
      • Day 0
      • Day 1
      • Day 2
      • Day 3
  • Certify
    • C# (Basic)
    • JavaScript (Basic)
    • SQL (Basic)
    • Rest API (Intermediate)
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. Prepare
  2. Python

Introduction

PreviousPythonNextSQL

Last updated 9 months ago

Was this helpful?

Say "Hello, World!" With Python

print("Hello, World!")

Python If-Else

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input().strip())
    if (n % 2) != 0:
        print("Weird")
    else:
        if n >= 2 and n <= 5:
            print("Not Weird")
        elif n >= 6 and n <= 20:
            print("Weird")
        elif 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())
    for i in range(n):
        print(i * i)

Write a function

def is_leap(year):
    leap = False
    
    # Write your logic here
    if year % 4 == 0:
        if year % 100 != 0 or year % 400 == 0:
            leap = True
            
    return leap

year = int(input())

Print Function

if __name__ == '__main__':
    n = int(input())
    for i in range(1, n+1):
        print(i, end="")
LogoPython: Division | HackerRankHackerRank
LogoWrite a function | HackerRankHackerRank
LogoSay "Hello, World!" With Python | HackerRankHackerRank
LogoArithmetic Operators | HackerRankHackerRank
LogoPython If-Else | HackerRankHackerRank
LogoLoops | HackerRankHackerRank
LogoPrint Function | HackerRankHackerRank