Skip to content

sunnyiisc/Python-Basic-Programs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic-Python

Some Basic Python Problems

Q1

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

Q2

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

Q3

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

Q4

(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

Q5

(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

Q6

(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

Q7

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

Q8

(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

Q9

(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