Sei sulla pagina 1di 7

1) Python Program to Add Two Numbers.

2) Python Program to Find the Square Root


3) Python Program to Calculate the Area of a Triangle
4) Python Program to Swap Two Variables using third variable
5) Python Program to Swap Two Variables without using third variable
6) Python Program to Check if a Number is Odd or Even
7) Python Program to Check if a Number is Positive, Negative or 0
8) Python Program to Convert Celsius To Fahrenheit
9) Python Program to Convert Kilometers to Miles
10) Python Program to Check Leap Year
11) Python Program to Find the Largest Among Three Numbers
12) Python Program to Find the Lowest Among Three Numbers
13) Python Program to Find the Sum of Natural Numbers
14) Python Program to Check Armstrong Number
15) Python Program to Print the Fibonacci sequence
16) Python Program to Check if a Number is Odd or Even
17) Find out the factorial of given number.
18) Find Numbers Divisible by Another Number

19) Python Program to Convert Kilometers to Miles.

20) Python Program to Convert Celsius To Fahrenheit

21) Ask the user to enter a temperature in Celsius. The program should print a message based on
the temperature:
• If the temperature is less than -273.15, print that the temperature is invalid because it is below
absolute zero.
• If it is exactly -273.15, print that the temperature is absolute 0.
• If the temperature is between -273.15 and 0, print that the temperature is below freezing.
• If it is 0, print that the temperature is at the freezing point.
• If it is between 0 and 100, print that the temperature is in the normal range.
• If it is 100, print that the temperature is at the boiling point.
• If it is above 100, print that the temperature is above the boiling point.
22) Accept age from user, check if the age is less than 18 display message you are minor and you
are not eligible to work. If age is between 18 to 60 display message eligible to work, fill your
details and apply else display message too old to work, collect your pension using nested if else.

23) Write a program which will accept an integer value below 10. Using this value, add those values
up to 10.(use while-else)

Example: Please Enter any integer below 10: 5


Value of Total From the While Loop is: 5
Value of Total From the While Loop is: 11
Value of Total From the While Loop is: 18
Value of Total From the While Loop is: 26
Value of Total From the While Loop is: 35 Value
of Total From the While Loop is: 45 You Value
is Greater Than 10 ==> This is from Else Block

24) How to create list by multiple ways?


# empty list
my_list = []
# list of integers
my_list = [1, 2, 3]

# list with mixed datatypes


my_list = [1, "Hello", 3.4]

# nested list
my_list = ["mouse", [8, 4, 6], ['a']]

25) How to access elements from a list? – List index

Nested list are accessed using nested indexing.


my_list = ['p','r','o','b','e']
# Output: p
print(my_list[0])

# Output: o
print(my_list[2])

# Output: e
print(my_list[4])

# Error! Only integer can be used for indexing


# my_list[4.0]

# Nested List
n_list = ["Happy", [2,0,1,5]]

# Nested indexing

# Output: a
print(n_list[0][1])

# Output: 5
print(n_list[1][3])
26) How to slice lists in Python?
my_list = ['p','r','o','g','r','a','m','i','z']
# elements 3rd to 5th
print(my_list[2:5])

# elements beginning to 4th


print(my_list[:-5])

# elements 6th to end


print(my_list[5:])

# elements beginning to end


print(my_list[:])

27) How to change or add elements to a list?


# mistake values
odd = [2, 4, 6, 8]

# change the 1st item


odd[0] = 1

# Output: [1, 4, 6, 8]
print(odd)

# change 2nd to 4th items


odd[1:4] = [3, 5, 7]

# Output: [1, 3, 5, 7]
print(odd)

28) How to delete or remove elements from a list?


my_list = ['p','r','o','b','l','e','m']

# delete one item


del my_list[2]

# Output: ['p', 'r', 'b', 'l', 'e', 'm']


print(my_list)

# delete multiple items


del my_list[1:5]

# Output: ['p', 'm']


print(my_list)
# delete entire list
del my_list

# Error: List not defined


print(my_list)

29) Write a Python program to sum all the items in a list.


30) Write a Python program to multiply all the items in a list.

31) Write a Python program to get the largest number from a list.

32) Write a Python program to get the smallest number from a list.

33) Write a Python program to count the number of strings where the string length is 2 or more and
the first and last character are same from a given list of strings.
Sample List : ['abc', 'xyz', 'aba', '1221']
Expected Result : 2

34) Write a Python program to check a list is empty or not.

35) Write a Python program to clone or copy a list.

36) Write a Python program to find the list of words that are longer than n from a given list of words.

37) Write a Python function that takes two lists and returns True if they have at least one common
member.

38) Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.
Sample List : ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
Expected Output : ['Green', 'White', 'Black']

39) Write a Python program to generate a 3*4*6 3D array whose each element is *.

40) Write a Python program to print the numbers of a specified list after removing even numbers
from it

41) Write a Python program to shuffle and print a specified list.


42) Write a Python program to generate and print a list of first and last 5 elements where the values
are square of numbers between 1 and 30 (both included).

43) Write a Python program to generate and print a list except for the first 5 elements, where the
values are square of numbers between 1 and 30 (both included).

44) Write a Python program to generate all permutations of a list in Python.

45) Write a Python program to get the difference between the two lists.

46) Write a Python program access the index of a list.


47) Write a Python program to convert a list of characters into a string.

48) Write a Python program to find the index of an item in a specified list.

49) Write a Python program to flatten a shallow list.

50) Write a Python program to append a list to the second list.

51) Write a Python program to select an item randomly from a list.

52) Write a python program to check whether two lists are circularly identical.

53) Write a Python program to find the second smallest number in a list.

54) Write a Python program to find the second largest number in a list.

55) Write a Python program to get unique values from a list.

56) Write a Python program to get the frequency of the elements in a list.

57) Write a Python program to count the number of elements in a list within a specified range.

58) Write a Python program to check whether a list contains a sublist.

59) Write a Python program to generate all sublists of a list.

60) Write a Python program using Sieve of Eratosthenes method for computing primes upto a
specified number.
Note: In mathematics, the sieve of Eratosthenes, (Ancient Greek: κόσκινον Ἐρατοσθένους,
kóskinon Eratosthénous) one of a number of prime number sieves, is a simple, ancient algorithm
for finding all prime numbers up to any given limit.

61) Write a Python program to create a list by concatenating a given list which range goes from 1 to
+++++ n.
Sample list : ['p', 'q']
n =5
Sample Output : ['p1', 'q1', 'p2', 'q2', 'p3', 'q3', 'p4', 'q4', 'p5', 'q5']

62) Write a Python program to get variable unique identification number or string.

63) Write a Python program to find common items from two lists.

64) Write a Python program to change the position of every n-th value with the (n+1)th in a list.
Sample list: [0,1,2,3,4,5]
Expected Output: [1, 0, 3, 2, 5, 4]

65) Write a Python program to convert a list of multiple integers into a single integer.
Sample list: [11, 33, 50]
Expected Output: 113350

66) Write a Python program to split a list based on first character of word.
67) Write a Python program to create multiple lists.

68) Write a Python program to find missing and additional values in two lists.

Sample data : Missing values in second list: b,a,c


Additional values in second list: g,h

69) Write a Python program to split a list into different variables.

70) Write a Python program to generate groups of five consecutive numbers in a list.
71) Write a Python program to convert a pair of values into a sorted unique array.

72) Write a Python program to select the odd items of a list.

73) Write a Python program to insert an element before each element of a list.

74) Write a Python program to print a nested list (each list on a new line) using the print () function.

75) Write a Python program to convert list to list of dictionaries.


Sample lists: ["Black", "Red", "Maroon", "Yellow"], ["#000000", "#FF0000", "#800000",
"#FFFF00"]
Expected Output: [{'color_name': 'Black', 'color_code': '#000000'}, {'color_name': 'Red',
'color_code': '#FF0000'}, {'color_name': 'Maroon', 'color_code': '#800000'}, {'color_name':
'Yellow', 'color_code': '#FFFF00'}]

76) Write a Python program to sort a list of nested dictionaries.

77) Write a Python program to split a list every Nth element.


Sample list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
Expected Output: [['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
78) Write a Python program to compute the similarity between two lists.
Sample data: ["red", "orange", "green", "blue", "white"], ["black", "yellow", "green", "blue"]
Expected Output:
Color1-Color2: ['white', 'orange', 'red']
Color2-Color1: ['black', 'yellow']

79) Write a Python program to create a list with infinite elements.

80) Write a Python program to concatenate elements of a list.

81) Write a Python program to remove key values pairs from a list of dictionaries.

82) Write a Python program to convert a string to a list.

83) Write a Python program to check if all items of a list is equal to a given string.

84) Write a Python program to get the depth of a dictionary.

85) Write a Python program to check if all dictionaries in a list are empty or not.

Sample list : [{},{},{}]


Return value : True
Sample list : [{1,2},{},{}]
Return value : False

86) Write a python program take input as string “Your python skills are starting to build” Covert this
string into upper case.
87) Take any string from user and check istitle function (function as return two value).

88) How to access an item of the dictionary by referring to its key name?

89) Write a python program to change value of specific item by referring to its key name.

90) How to add item in a dictionary, write a program in a python.

Potrebbero piacerti anche