title-img


Finding the Percentage

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 (20+50+70)/3 = 50. Input Format: The first line contains the integer n, the number of stude

View Solution →

Lists

Consider a list (list = []). You can perform the following commands: 1. insert i e: Insert integer e at position i. 2. print: Print the list. 3. remove e: Delete the first occurrence of integer e . 4. append e: Insert integer e at the end of the list. 5. sort: Sort the list. 6. pop: Pop the last element from the list. 7. reverse: Reverse the list . Initialize your list and read in the value of n followed by n lines of commands where each comma

View Solution →

Tuples

Task: Given an integer, n, and n space-separated integers as input, create a tuple, t, of those n integers. Then compute and print the result of hash(t). Note: hash() is one of the functions in the __builtins__ module, so it need not be imported. Input Format: The first line contains an integer, n, denoting the number of elements in the tuple. The second line contains n space-separated integers describing the elements in tuple t. Output Format: Print the r

View Solution →

sWAP cASE

You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa. For Example: Www.HackerRankSolution.in → wWW.hACKERrANKsOLUTION.IN Pythonist 2 → pYTHONIST 2 Input Format: A single line containing a string S. Constraints: 0<len(S)<=1000 Output Format: Print the modified string S.

View Solution →

String Split and Join

In Python, a string can be split on a delimiter. Example: >>> a = "this is a string" >>> a = a.split(" ") # a is converted to a list of strings. >>> print a ['this', 'is', 'a', 'string'] Joining a string is simple: >>> a = "-".join(a) >>> print a this-is-a-string Task: You are given a string. Split the string on a " " (space) delimiter and join using a - hyphen. Input Format: The first line contains a string cons

View Solution →