0% found this document useful (0 votes)
25 views7 pages

Assignment - 2 Python Aa

The document contains Python code for solving problems on HackerRank including problems on loops, arrays, strings, and regex. It provides the code and output for multiple problems of varying difficulties from easy to hard.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views7 pages

Assignment - 2 Python Aa

The document contains Python code for solving problems on HackerRank including problems on loops, arrays, strings, and regex. It provides the code and output for multiple problems of varying difficulties from easy to hard.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

OPEN ELECTIVE - PYTHON

ASSIGNMENT -2

NAME : AJMEERA ANIL

ROLL NO : 160120802022

DEPT : CHEMICAL ENGNEERING


QUESTION NO : 1 (HACKER RANK) MEDIUM ONE

CODE:

for num in range(1, int(input())):


print((10**num//9)*num)

OUTPUT:
QUESTION NO : 2 (HACKER RANK) MEDIUM ONE

CODE:

n, m = (int(x) for x in input().split())


arr = input().split()
likes = set(input().split())
dislikes = set(input().split())
happiness = 0
for _, num in enumerate(arr):
happiness += 1 if num in likes else 0
happiness -= 1 if num in dislikes else 0
print(happiness)
OUT PUT :
QUESTION NO: 8 (HACKER RANK) MEDIUM ONE

CODE :

def minion_game(string):
vowels = 'AEIOU'
kevin_score, stuart_score = 0, 0
strlen = len(string)

for i in range(0, strlen):


if string[i] in vowels:
kevin_score += strlen-i
else:
stuart_score += strlen-i

if kevin_score > stuart_score:


print(f"Kevin {kevin_score}")
elif kevin_score < stuart_score:
print(f"Stuart {stuart_score}")
else:
print("Draw")

if __name__ == '__main__':
s = input()
minion_game(s)
OUT PUT :

QUESTION NO: 9 (HACKER RANK ) HARD ONE


CODE:

from itertools import product


k,m = map(int,input().split())

nums = [[int(j)**2 for j in input().split()[1:]] for _ in range(k)]


print(max(sum(i)%m for i in product(*nums)))

OUT PUT :

QUESTION NO : ( HACKER RANK ) HARD ONE


CODE :

regex_integer_in_range = r"^[1-9]\d{5}$" # Do not delete 'r'.


regex_alternating_repetitive_digit_pair = r"(\d)(?=\d\1)" # Do not d
elete 'r'.

import re
P = input()

print (bool(re.match(regex_integer_in_range, P))


and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)

import re
P = input()

print (bool(re.match(regex_integer_in_range, P))


and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)

OUTPUT :

You might also like