[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Python Exercise

The document outlines various Python programming tasks including user input handling, string manipulation, list operations, and set operations. It covers formatting numbers, creating new strings from existing ones, and counting occurrences of elements in a list. Additionally, it includes examples of working with odd and even indexed elements from lists and set intersections.

Uploaded by

sabariv688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Python Exercise

The document outlines various Python programming tasks including user input handling, string manipulation, list operations, and set operations. It covers formatting numbers, creating new strings from existing ones, and counting occurrences of elements in a list. Additionally, it includes examples of working with odd and even indexed elements from lists and set intersections.

Uploaded by

sabariv688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Use Python 3’s built-in function input() to accept user inpu.

Convert user input to the


integer type using the int() constructor.

2. Use the sep parameter of the print() function to define the separator symbol
between each word.

3. Use the %o formatting code within the print() function to format a decimal number
as octal.

4. Use the %.2f formatting code within the print() function to format a float number to
two decimal places.

5. Get a list of numbers as input from a user and calculate the sum of it

6. Create a string made of the first, middle and last character.

7. Create a string made of the middle three characters.

8. Append new string in the middle of a given string

9. Create a new string made of the first, middle, and last characters of each input string

10. Write a code to create a new list using odd-indexed elements


from the first list and even-indexed elements from the second
Given two lists, l1 and l2, write a program to create a third
list l3 by picking an odd-index element from the list l1 and
even index elements from the list l2.
Given:
l1 = [3, 6, 9, 12, 15, 18, 21]
l2 = [4, 8, 12, 16, 20, 24, 28]
Expected Output:
Element at odd-index positions from list one
[6, 12, 18]
Element at even-index positions from list two
[4, 12, 20, 28]

Printing Final third list


[6, 12, 18, 4, 12, 20, 28]

11. Count the occurrence of each element from a list

Write a program to iterate a given list and count the occurrence


of each element and create a dictionary to show the count of
each element.

12. Set Intersection and Removal


Write a code to find the intersection (common) of two sets and
remove those elements from the first set.

You might also like