100% found this document useful (1 vote)
322 views

Python Programs List

The document contains Python programs using various Python concepts like control statements, lists, regular expressions, and dictionaries. Some key programs include: 1. A program to find numbers between 1500-2700 divisible by 7 and multiple of 5. 2. Programs to convert temperatures between Celsius and Fahrenheit and to guess a random number between 1-9. 3. Programs involving lists - summing/multiplying items, finding min/max, removing duplicates etc. 4. Programs using regular expressions to match strings based on patterns. 5. Programs involving dictionaries - sorting, adding/checking keys, merging, mapping lists to dicts etc.

Uploaded by

manjulakinnal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
322 views

Python Programs List

The document contains Python programs using various Python concepts like control statements, lists, regular expressions, and dictionaries. Some key programs include: 1. A program to find numbers between 1500-2700 divisible by 7 and multiple of 5. 2. Programs to convert temperatures between Celsius and Fahrenheit and to guess a random number between 1-9. 3. Programs involving lists - summing/multiplying items, finding min/max, removing duplicates etc. 4. Programs using regular expressions to match strings based on patterns. 5. Programs involving dictionaries - sorting, adding/checking keys, merging, mapping lists to dicts etc.

Uploaded by

manjulakinnal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PYTHON PROGRAMS USING CONTROL STATEMENTS

1. Write a Python program to find those numbers which are divisible by 7 and multiple of 5,
between 1500 and 2700 (both included).

2. Write a Python program to convert temperatures to and from celsius, fahrenheit.


[ Formula : c/5 = f-32/9 [ where c = temperature in celsius and f = temperature in fahrenheit ]
Expected Output :
60°C is 140 in Fahrenheit
45°F is 7 in Celsius

3. Write a Python program to guess a number between 1 to 9.


Note : User is prompted to enter a guess. If the user guesses wrong then the prompt appears
again until the guess is correct, on successful guess, user will get a "Well guessed!" message,
and the program will exit.

4. Write a Python program to construct the following pattern, using a nested for loop.

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

5. Write a Python program that accepts a word from the user and reverse it.

6. 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

7. Write a Python program that prints each item and its corresponding type from the
following list.
Sample List : datalist = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12], {"class":'V',
"section":'A'}]

8. Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.
Note : Use 'continue' statement.
Expected Output : 0 1 2 4 5

9. 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

10. Write a Python program which iterates the integers from 1 to 50. For multiples of three
print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers
which are multiples of both three and five print "FizzBuzz".

PYTHON PROGRAMS USING LISTS

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

2. Write a Python program to multiplies all the items in a list.

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

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

5. 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

6. Write a Python program to get a list, sorted in increasing order by the last element in each
tuple from a given list of non-empty tuples.
Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
Expected Result : [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]

7. Write a Python program to remove duplicates from a list.

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

9. Write a Python program to clone or copy a list.


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

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

12. 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']

PYTHON PROGRAMS USING REGULAR EXPRESSIONS

1. Write a Python program to check that a string contains only a certain set of characters (in
this case a-z, A-Z and 0-9).

2. Write a Python program that matches a string that has an a followed by zero or more b's.

3. Write a Python program that matches a string that has an a followed by one or more b's.

4. Write a Python program that matches a string that has an a followed by zero or one 'b'.

5. Write a Python program that matches a string that has an a followed by three 'b'.

6. Write a Python program that matches a string that has an a followed by two to three 'b'.

7. Write a Python program to find sequences of lowercase letters joined with a underscore.

8. Write a Python program to find the sequences of one upper case letter followed by lower
case letters.
9. Write a Python program that matches a string that has an 'a' followed by anything, ending
in 'b'.

10. Write a Python program that matches a word at the beginning of a string.

11. Write a Python program that matches a word at the end of string, with optional
punctuation.

12. Write a Python program that matches a word containing 'z'.

PYTHON PROGRAMS USING DICTIONARIES

1. Write a Python script to sort (ascending and descending) a dictionary by value.

2. Write a Python script to add a key to a dictionary.

Sample Dictionary : {0: 10, 1: 20}


Expected Result : {0: 10, 1: 20, 2: 30}

3. Write a Python script to concatenate following dictionaries to create a new one.

Sample Dictionary :
dic1={1:10, 2:20}
dic2={3:30, 4:40}
dic3={5:50,6:60}
Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

4. Write a Python script to check whether a given key already exists in a dictionary.

5. Write a Python program to iterate over dictionaries using for loops.


6. 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}

7. Write a Python script to print a dictionary where the keys are numbers between 1 and 15
(both included) and the values are square of keys.
Sample Dictionary
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14:
196, 15: 225}

8. Write a Python script to merge two Python dictionaries.

9. Write a Python program to iterate over dictionaries using for loops.

10. Write a Python program to sum all the items in a dictionary.

11. Write a Python program to multiply all the items in a dictionary.

12. Write a Python program to remove a key from a dictionary.

13. Write a Python program to map two lists into a dictionary.

You might also like