I found an interesting problem on https://www.hackerrank.com/challenges/finding-the-percentage/problem:
=====Problem Statement=====
The provided code stub will read in a dictionary containing key/value pairs of name:[marks] for a list of students. Print the average of the marks array for the student name provided, showing 2 places after the decimal.

=====Example=====
marks key:value pairs are
'alpha': [20,30,40]
'beta': [30,50,70]
query_name = 'beta'
The query_name is 'beta'. beta's average score is (30+50+70)/3 = 50

=====Input Format=====
The first line contains the integer n, the number of students' records. The next n lines contain the names and marks obtained by a student, each value separated by a space. The final line contains query_name, the name of a student to query.

=====Constraints=====
2≤n≤10
0≤marks[i]≤100
length of marks arrays = 3

=====Output Format=====
Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.

I tried it in Python, but could not do it. Can you solve it?

def get_avg(marks, student):
    return (sum(marks[student])/len(marks[student]))

def __starting_point():
    n = int(input())
    student_marks = {}
    for _ in range(n):
        name, *line = input().split()
        scores = list(map(float, line))
        student_marks[name] = scores
    query_name = input()
    print(("{:.2f}".format(get_avg(student_marks, query_name))))

__starting_point()


I found an interesting problem on https://www.hackerrank.com/challenges/list-comprehensions/problem:
=====Problem Statement=====
Let's learn about list comprehensions! You are given three integers x, y and z representing the dimensions of a cuboid along with an integer n. Print a list of all possible coordinates given by (i,j,k) on a 3D grid where the sum of i+j+k is not equal to n. Here, 0≤i≤x;0≤j≤y;0≤k≤z. Please use list comprehensions rather than multiple loops, as a learning exercise.

=====Example=====
x = 1
y = 1
z = 2
n = 3
All permutations of [i,j,k] are:
[[0,0,0],[0,0,1],[0,0,2],[0,1,0],[0,1,1],[0,1,2],[1,0,0],[1,0,1],[1,0,2],[1,1,0],[1,1,1],[1,1,2]]
Print an array of the elements that do not sum to n = 3
[[0,0,0],[0,0,1],[0,0,2],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,2]]

=====Input Format=====
Four integers x, y, z and n, each on a separate line.

=====Constraints=====
Print the list in lexographic increasing order

I tried it in Python, but could not do it. Can you solve it?

def __starting_point():
    x = int(input())
    y = int(input())
    z = int(input())
    n = int(input())

    print([ [ i, j, k] for i in range(x + 1) for j in range(y + 1) for k in range(z + 1) if ( (i + j + k) != n )])

__starting_point()


I found an interesting problem on https://www.hackerrank.com/challenges/map-and-lambda-expression/problem:
=====Problem Statement=====
Let's learn some new Python concepts! You have to generate a list of the first N fibonacci numbers, 0 being the first number. Then, apply the map function and a lambda expression to cube each fibonacci number and print the list.

Concept

The map() function applies a function to every member of an iterable and returns the result. It takes two parameters: first, the function that is to be applied and secondly, the iterables.
Let's say you are given a list of names, and you have to print a list that contains the length of each name.

>> print (list(map(len, ['Tina', 'Raj', 'Tom'])))
[4, 3, 3]

Lambda is a single expression anonymous function often used as an inline function. In simple words, it is a function that has only one line in its body. It proves very handy in functional and GUI programming.

>> sum = lambda a, b, c: a + b + c
>> sum(1, 2, 3)
6

Note:

Lambda functions cannot use the return statement and can only have a single expression. Unlike def, which creates a function and assigns it a name, lambda creates a function and returns the function itself. Lambda can be used inside lists and dictionaries.

=====Input Format=====
One line of input: an integer N.

=====Output Format=====
A list on a single line containing the cubes of the first N fibonacci numbers.

I tried it in Python, but could not do it. Can you solve it?

# Enter your code here. Read input from STDIN. Print output to STDOUT
def sqr(a):
    return a*a*a
n=int(input())
if(n==0):
    print("[]")
elif(n==1):
    print("[0]")
else:
    ar=[0]*n
    ar[0]=0
    ar[1]=1
    for i in range(2,n):
        ar[i]=ar[i-1]+ar[i-2]

    ar=list(map(sqr,ar))
    print(ar)


I found an interesting problem on https://www.hackerrank.com/challenges/py-collections-namedtuple/problem:
=====Function Descriptions=====
collections.namedtuple()

Basically, namedtuples are easy to create, lightweight object types.
They turn tuples into convenient containers for simple tasks.
With namedtuples, you don’t have to use integer indices for accessing members of a tuple.

Example
Code 01
>>> from collections import namedtuple
>>> Point = namedtuple('Point','x,y')
>>> pt1 = Point(1,2)
>>> pt2 = Point(3,4)
>>> dot_product = ( pt1.x * pt2.x ) +( pt1.y * pt2.y )
>>> print dot_product
11

Code 02
>>> from collections import namedtuple
>>> Car = namedtuple('Car','Price Mileage Colour Class')
>>> xyz = Car(Price = 100000, Mileage = 30, Colour = 'Cyan', Class = 'Y')
>>> print xyz
Car(Price=100000, Mileage=30, Colour='Cyan', Class='Y')
>>> print xyz.Class
Y

=====Problem Statement=====
Dr. John Wesley has a spreadsheet containing a list of student's IDs, marks, class and name.
Your task is to help Dr. Wesley calculate the average marks of the students.
Average = Sum of all marks / Total students

Note:
1. Columns can be in any order. IDs, marks, class and name can be written in any order in the spreadsheet.
2. Column names are ID, MARKS, CLASS and NAME. (The spelling and case type of these names won't change.)

=====Input Format=====
The first line contains an integer N, the total number of students.
The second line contains the names of the columns in any order.
The next N lines contains the marks, IDs, name and class, under their respective column names.

=====Constraints=====
0<N≤100

=====Output Format=====
Print the average marks of the list corrected to 2 decimal places.

I tried it in Python, but could not do it. Can you solve it?

#!/usr/bin/env python3

from collections import namedtuple

def __starting_point():
    s_num = int(input().strip())
    tuple_fields = input().strip().split()

    student = namedtuple('student', tuple_fields)
    library = []
    res = 0

    for _ in range(s_num):
        st_info = input().strip().split()
        library.append(student(st_info[0], st_info[1], st_info[2], st_info[3]))

    for el in library:
        res += int(el.MARKS)

    print(res/s_num)
__starting_point()


I found an interesting problem on https://www.hackerrank.com/challenges/py-if-else/problem:
=====Problem Statement=====
Given an integer, n, perform the following conditional actions:
If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20, print Not Weird

=====Input Format=====
A single line containing a positive integer, n.

=====Constraints=====
1≤n≤100

=====Output Format=====
Print Weird if the number is weird. Otherwise, print Not Weird.

I tried it in Python, but could not do it. Can you solve it?

def __starting_point():
    n = int(input())
    if n % 2 == 1 or 6 <= n <= 20:
        print("Weird")
    else:
        print("Not Weird")

__starting_point()


I found an interesting problem on https://www.hackerrank.com/challenges/standardize-mobile-number-using-decorators/problem:
=====Problem Statement=====
Let's dive into decorators! You are given N mobile numbers. Sort them in ascending order then print them in the standard format shown below:
+91 xxxxx xxxxx

The given mobile numbers may have +91, 91 or 0 written before the actual 10 digit number. Alternatively, there may not be any prefix at all. Alternatively, there may not be any prefix at all.

=====Input Format=====
The first line of input contains an integer N, the number of mobile phone numbers. N lines follow each containing a mobile number.

=====Output Format=====
Print N mobile numbers on separate lines in the required format.

I tried it in Python, but could not do it. Can you solve it?

# Enter your code here. Read input from STDIN. Print output to STDOUT
n=int(input())
ar=[]
for i in range(0,n):
    tmp_str=input()
    tmp_str=tmp_str[len(tmp_str)-10:]
    ar.append(tmp_str)

ar.sort()
for i in range(0,len(ar)):
    print(("+91 "+ar[i][:5]+" "+ar[i][5:]))


I found an interesting problem on https://www.hackerrank.com/challenges/symmetric-difference/problem:
=====Function Descriptions=====
Objective
Today, we're learning about a new data type: sets.

Concept

If the inputs are given on one line separated by a space character, use split() to get the separate values in the form of a list:

>> a = raw_input()
5 4 3 2
>> lis = a.split()
>> print (lis)
['5', '4', '3', '2']

If the list values are all integer types, use the map() method to convert all the strings to integers.

>> newlis = list(map(int, lis))
>> print (newlis)
[5, 4, 3, 2]

Sets are an unordered bag of unique values. A single set contains values of any immutable data type.

CREATING SETS

>> myset = {1, 2} # Directly assigning values to a set
>> myset = set()  # Initializing a set
>> myset = set(['a', 'b']) # Creating a set from a list
>> myset
{'a', 'b'}

MODIFYING SETS

Using the add() function:

>> myset.add('c')
>> myset
{'a', 'c', 'b'}
>> myset.add('a') # As 'a' already exists in the set, nothing happens
>> myset.add((5, 4))
>> myset
{'a', 'c', 'b', (5, 4)}

Using the update() function:

>> myset.update([1, 2, 3, 4]) # update() only works for iterable objects
>> myset
{'a', 1, 'c', 'b', 4, 2, (5, 4), 3}
>> myset.update({1, 7, 8})
>> myset
{'a', 1, 'c', 'b', 4, 7, 8, 2, (5, 4), 3}
>> myset.update({1, 6}, [5, 13])
>> myset
{'a', 1, 'c', 'b', 4, 5, 6, 7, 8, 2, (5, 4), 13, 3}

REMOVING ITEMS

Both the discard() and remove() functions take a single value as an argument and removes that value from the set. If that value is not present, discard() does nothing, but remove() will raise a KeyError exception.

>> myset.discard(10)
>> myset
{'a', 1, 'c', 'b', 4, 5, 7, 8, 2, 12, (5, 4), 13, 11, 3}
>> myset.remove(13)
>> myset
{'a', 1, 'c', 'b', 4, 5, 7, 8, 2, 12, (5, 4), 11, 3}

COMMON SET OPERATIONS Using union(), intersection() and difference() functions.

>> a = {2, 4, 5, 9}
>> b = {2, 4, 11, 12}
>> a.union(b) # Values which exist in a or b
{2, 4, 5, 9, 11, 12}
>> a.intersection(b) # Values which exist in a and b
{2, 4}
>> a.difference(b) # Values which exist in a but not in b
{9, 5}

The union() and...

I tried it in Python, but could not do it. Can you solve it?

#!/usr/bin/env python3

def __starting_point():
    M = int(input().strip())
    set_m = set(map(int, input().strip().split(' ')))

    N = int(input().strip())
    set_n = set(map(int, input().strip().split(' ')))

    for el in sorted(set_m ^ set_n):
        print(el)

__starting_point()


I found an interesting problem on https://www.hackerrank.com/challenges/validate-a-roman-number/problem:
=====Problem Statement=====
You are given a string, and you have to validate whether it's a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral.

=====Input Format=====
A single line of input containing a string of Roman characters.

=====Output Format=====
Output a single line containing True or False according to the instructions above.

=====Constraints=====
The number will be between 1 and 3999 (both included).

I tried it in Python, but could not do it. Can you solve it?

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
def my_func(s):
    s = s.upper()
    ##res=re.match(r'^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$',s)
    res=re.search(r'^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$',s)
    if(s=="MMMM"):
        print("False")
    else:
        if res:
            print("True")
        else:
            print("False")
my_func(input())


I found an interesting problem on https://www.hackerrank.com/challenges/validate-list-of-email-address-with-filter/problem:
=====Problem Statement=====
You are given an integer N followed by N email addresses. Your task is to print a list containing only valid email addresses in lexicographical order.
Valid email addresses must follow these rules:
It must have the username@websitename.extension format type.
The username can only contain letters, digits, dashes and underscores.
The website name can only have letters and digits.
The maximum length of the extension is 3.

Concept

A filter takes a function returning True or False and applies it to a sequence, returning a list of only those members of the sequence where the function returned True. A Lambda function can be used with filters.

Let's say you have to make a list of the squares of integers from 0 to 9 (both included).

>> l = list(range(10))
>> l = list(map(lambda x:x*x, l))

Now, you only require those elements that are greater than 10 but less than 80.

>> l = list(filter(lambda x: x > 10 and x < 80, l))

Easy, isn't it?

=====Input Format=====
The first line of input is the integer N, the number of email addresses.
N lines follow, each containing a string.

=====Constraints=====
Each line is a non-empty string.

=====Output Format=====
Output a list containing the valid email addresses in lexicographical order. If the list is empty, just output an empty list, [].

I tried it in Python, but could not do it. Can you solve it?

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
n=int(input())
ar=[]
for i in range(0,n):
    s=input()
    t=re.search(r"^[a-zA-Z][\w-]*@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$",s)
    if t:
        ar.append(s)
ar.sort()
print(ar)


I found an interesting problem on https://www.hackerrank.com/challenges/validating-the-phone-number/problem:
=====Problem Statement=====
Let's dive into the interesting topic of regular expressions! You are given some input, and you are required to check whether they are valid mobile numbers.

Concept
A valid mobile number is a ten digit number starting with a 7, 8, or 9.

=====Input Format=====
The first line contains an integer N, the number of inputs.
N lines follow, each containing some string.

=====Constraints=====
1≤N≤10
2≤len(Number)≤15

=====Output Format=====
For every string listed, print "YES" if it is a valid mobile number and "NO" if it is not on separate lines. Do not print the quotes.

I tried it in Python, but could not do it. Can you solve it?

import re

n = int(input().strip())

for _ in range(n):
    tel = input().strip()
    pattern = '^[789][0-9]{9}$'
    print("{}".format("YES" if bool(re.match(pattern, tel)) else "NO"))


I found an interesting problem on https://www.hackerrank.com/challenges/words-score/problem:
=====Problem Statement=====
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
Consider that vowels in the alphabet are a, e, i, o, u and y.
Function score_words takes a list of lowercase words as an argument and returns a score as follows:
The score of a single word is 2 if the word contains an even number of vowels. Otherwise, the score of this word is 1. The score for the whole list of words is the sum of scores of all words in the list.
Debug the given function score_words such that it returns a correct score.
Your function will be tested on several cases by the locked template code.

=====Input Format=====
The input is read by the provided locked code template. In the first line, there is a single integer n denoting the number of words. In the second line, there are n space-separated lowercase words.

=====Constraints=====
1≤n≤20
Each word has at most 20 letters and all letters are English lowercase letters

=====Output Format=====
The output is produced by the provided and locked code template. It calls function score_words with the list of words read from the input as the argument and prints the returned score to the output.

I tried it in Python, but could not do it. Can you solve it?

def is_vowel(letter):
    return letter in ['a', 'e', 'i', 'o', 'u', 'y']

def score_words(words):
    score = 0
    for word in words:
        num_vowels = 0
        for letter in word:
            if is_vowel(letter):
                num_vowels += 1
        if num_vowels % 2 == 0:
            score += 2
        else:
            score += 1
    return score


I found an interesting problem on https://www.hackerrank.com/challenges/xml-1-find-the-score/problem:
=====Problem Statement=====
You are given a valid XML document, and you have to print its score. The score is calculated by the sum of the score of each element. For any element, the score is equal to the number of attributes it has.

=====Input Format=====
The first line contains N, the number of lines in the XML document.
The next N lines follow containing the XML document.

=====Output Format=====
Output a single line, the integer score of the given XML document.

I tried it in Python, but could not do it. Can you solve it?

def get_attr_number(node):
    return len(node.attrib) + sum([get_attr_number(child) for child in node])


I found an interesting problem on https://www.hackerrank.com/challenges/xml2-find-the-maximum-depth/problem:
=====Problem Statement=====
You are given a valid XML document, and you have to print the maximum level of nesting in it. Take the depth of the root as 0.

=====Input Format=====
The first line contains N, the number of lines in the XML document.
The next N lines follow containing the XML document.

=====Output Format=====
Output a single line, the integer value of the maximum level of nesting in the XML document.

I tried it in Python, but could not do it. Can you solve it?

# Enter your code here. Read input from STDIN. Print output to STDOUT
xml_str=""
n=int(input())
for i in range(0,n):
    tmp_str=input()
    xml_str=xml_str+tmp_str

import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml_str))
root=tree.getroot()
ar=[]
def cnt_node(node):
    return max( [0] + [cnt_node(child)+1 for child in node])
cnt=cnt_node(root)
print(cnt)