Some Basic Python Problems
Write a Python function that takes a list of words and returns the length of the longest one. word list: (["PHP", "python", "zekelabs"])
Python Code for Q1 Click Here
Write a Python program to count the occurrences of each word in a given sentence
- word: 'the quick brown fox jumps over the lazy dog.'
Python Code for Q2 Click Here
Write a Python function that takes two lists and returns True if they have at least one common member
- list 1: [1,2,3,4,5] and list 2 : [5,6,7,8,9]))
- List -1([1,2,3,4,5], and List 2: [6,7,8,9]))
Python Code for Q3 Click Here
(a) Write a Python program to find the second smallest number in a list number: [1, 2, -8, -2, 0] (b) Write a Python program to find the second largest number in a list. number: [1, 2, -8, -2, 0]
Python Code for Q4 Click Here
Python Code for Q4 Alternative with single for loop Click Here
(a) Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x, x*x)
- Sample Dictionary ( n = 5) :
- Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25} (b) Write a Python program to combine two dictionary adding values for common keys
- d1 = {'a': 100, 'b': 200, 'c':300}
- d2 = {'a': 300, 'b': 200, 'd':400} Sample output: Counter({'a': 400, 'b': 400, 'd': 400, 'c': 300})
Python Code for Q5 Click Here
Python Code for Q5 Alternative with single for loop Click Here
(a)Write a Python program to add an item (i.e.any number) in a tuple
- tuplex = (4, 6, 2, 8, 3, 1) (b) Write a Python program to convert a tuple to a string.
- tup = ('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's') (c)Write a Python program to find the repeated items of a tuple
- tuplex = 2, 4, 5, 6, 2, 3, 4, 4, 7 (d) Write a Python program to convert a tuple to a dictionary.
- tuplex = ((2, "w"),(3, "r"))
Python Code for Q6 Click Here
Write a Python program to count the number of even and odd numbers from a series of numbers.
- Sample numbers : numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
- Expected Output :
- Number of even numbers : 5
- Number of odd numbers : 4
Python Code for Q7 Click Here
(a) Write a Python program to get the Fibonacci series between 0 to 50. Note : The Fibonacci Sequence is the series of numbers :
- 0, 1, 1, 2, 3, 5, 8, 13, 21, ....
- Every next number is found by adding up the two numbers before it.
- Expected Output : 1 1 2 3 5 8 13 21 34 (b) Write a Python program to create the multiplication table (from 1 to 10) of a number.
Python Code for Q8 Click Here
(a) Write a Python function to find the Max of three numbers. (b) Write a Python function to sum all the numbers in a list (c) Write a Python function to multiply all the numbers in a list
Python Code for Q9 Click Here