Hi All,
Today we had a very successful hands on session on Python. Entire NSL Hall was jam packed with students enthusiastic about Python.
As said after the workshop, we are running a contest for people who attended today's workshop. Here are some questions for you to try - fire up your python shell and try to solve as many as you can.
We have two laptop bags to give away. You need to have solved at-least 10 q to be eligible for the prize. Once you have solved 10 q - send in a mail to
an...@stab-iitb.org with the question number and solution. Should there be more than 2 contenders for the prize, winner will be selected using
random.org
Deadline for this is Sunday 20th Jan 11:59 pm
- Write a function that takes a list as input and returns the minimum element of the list. Try to do it in different ways! Don't use the built-in functions!
- Write a function to find the number of words in a sentence. Try to do it in one line
- Write a function to find the factorial of a positive integer. Try to do it in one line!
- Write a function to add only the even elements of a list.
- Write a function to add all numbers between 1 and 999 (both included) which are divisible by either 3 or 5. Try to do it in one line!
- Write a function to return all prefix strings of the string 'aaababbbabababbabbbababbaa' which do not end in 'a'. Try to do it in one line!
- Write a function to find the sum of digits of a number. Try to do it in one line! Try to do it with and without using dictionaries.
- Write a function to remove repeated elements from a list. Do it in different ways.
- Write a function that takes a string of digits as input from a user, converts it to a number, and checks if it is a palindrome
- Write a function that takes a string as input from the user and returns a string with the alternate digits dropped
- Write a function that takes a number as input and checks if it is prime or not. Make it as fast as possible.
- Write a function that takes a list and duplicates each element of it e.g. [1,2,3,3] => [1,1,2,2,3,3,3,3]
- Write a function that takes a string as input and returns a string containing only the characters at odd positions e.g. 'abcd' => 'ac'
- Write a function that takes a list as input and returns a list that has the same elements as the input list, but the right half of the output list is sorted whereas the left halves are reverse sorted. e.g. [4,7,9,3,2,6,5,1] => [9,7,4,3,1,2,5,6] as the left half of the input list is [4,7,9,3] and the right half of the input list is [2,6,5,1]
- Write a function that, given a string, removes from the string any * character, or any character that's one to the left or one to the right of a * character. Examples: "adf*lp" --> "adp"
"a*o" --> ""
"*dech*" --> "ec"
"de**po" --> "do"
"sa*n*ti" --> "si"
"abc" --> "abc"
- Write a function to return all permutations of a given string. Don't cheat by using the permutations function in the standard library!
- Write a function that takes a number between 0 and 1 as input (call it x) and returns a random string consisting of 0s and 1s such that the probability of getting '1' when a character is randomly chosen from the string = x.
Thanks to Rohan Prinja for taking this session.
Anil Shanbhag
Manager, WnCC