Skip to content

Shubham-Sharma-India/HackerRank---Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

HackerRank---Python

  1. Say "Hello, World!" With Python
if __name__ == '__main__':
    print "Hello, World!"
  1. Find the Runner-Up Score!
if __name__ == '__main__':
    n = int(raw_input())
    arr = map(int, raw_input().split())
    print(sorted(list(set(arr)))[-2])
  1. Tuples
if __name__ == '__main__':
    n = int(raw_input())
    integer_list = map(int, raw_input().split())
    t = tuple(integer_list)
    print(hash(t));
  1. Lists
if __name__ == '__main__':
    N = int(raw_input())
    Output = [];
    for i in range(0,N):
        ip = raw_input().split();
        if ip[0] == "print":
            print(Output)
        elif ip[0] == "insert":
            Output.insert(int(ip[1]),int(ip[2]))
        elif ip[0] == "remove":
            Output.remove(int(ip[1]))
        elif ip[0] == "pop":
            Output.pop();
        elif ip[0] == "append":
            Output.append(int(ip[1]))
        elif ip[0] == "sort":
            Output.sort();
        else:
            Output.reverse();
  1. Nested Lists
if __name__ == '__main__':
    students = []
    scores = []
    for _ in range(int(raw_input())):
        name = raw_input()
        score = float(raw_input())
        scores.append(score)
        students.append([name, score])
    
    count = scores.count(min(scores))
    for i in range(count):
        scores.remove(min(scores))
        
    secondHigh = min(scores)
    
    students.sort()
    
    output = [x for x in students if x[1] == secondHigh]
    
    for i in output:
        print(i[0])
  1. Print Function
if __name__ == '__main__':
    n = int(input())
    for i in range(1, n+1):
        print(i, end="")
  1. Write a function
def is_leap(year):
    leap = False
    
    # Write your logic here
    if (year % 400 == 0) and (year % 100 == 0):
        return True
    if (year % 4 == 0) and (year % 100 != 0):
        return True
    return leap
  1. Loops
if __name__ == '__main__':
    n = int(input())
for i in range (0, n):
    print(i*i)
  1. 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")
elif (n >= 2) and (n <= 5):
    print("Not Weird")
elif (n >= 6) and (n <= 20):
    print("Weird")
elif (n > 20):
    print("Not Weird")
  1. Python: Division
from __future__ import division

if __name__ == '__main__':
    a = int(raw_input())
    b = int(raw_input())
    print(a // b)
    print(a / b)
  1. Arithmetic Operators
if __name__ == '__main__':
    a = int(raw_input())
    b = int(raw_input())
    print(a + b)
    print(a - b)
    print(a * b)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published