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

Python Hands On

The document outlines six programming assignments aimed at practicing various Python concepts. Assignments cover simple data processing, list manipulation, string operations, file handling, error handling, and object-oriented programming. Each assignment includes specific tasks and objectives to enhance the user's coding skills.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Hands On

The document outlines six programming assignments aimed at practicing various Python concepts. Assignments cover simple data processing, list manipulation, string operations, file handling, error handling, and object-oriented programming. Each assignment includes specific tasks and objectives to enhance the user's coding skills.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 1: Simple Data Processing and Output

●​ Objective: To practice basic input, data types, and formatted output.


●​ Task:
1.​ Write a Python script that asks the user for their name, age, and favorite
programming language.
2.​ Store this information in variables.
3.​ Print a formatted message like: "Hello, [Name]! You are [Age] years old and
your favorite programming language is [Language]."
4.​ Additionally, calculate the user's birth year based on their age and the current
year (you can hardcode the current year for simplicity) and print it.

Assignment 2: List Manipulation and Control Flow


●​ Objective: To practice list operations, loops, and conditional statements.
●​ Task:
1.​ Create a list of 10 random integers.
2.​ Write a loop that iterates through the list.
3.​ Inside the loop, check if each number is even or odd.
4.​ Create two new lists: one for even numbers and one for odd numbers.
5.​ Append each number to the appropriate list.
6.​ Print both the even and odd number lists.

Assignment 3: String Operations and Functions


●​ Objective: To practice string manipulation and defining functions.
●​ Task:
1.​ Write a function that takes a string as input.
2.​ Inside the function, perform the following:
■​ Count the number of vowels (a, e, i, o, u) in the string.
■​ Count the number of consonants.
■​ Reverse the string.
3.​ Return a dictionary containing the vowel count, consonant count, and
reversed string.
4.​ Get a string input from the user and call the function.
5.​ Print the returned dictionary.

Assignment 4: Dictionaries and File Handling (Simple)


●​ Objective: To practice using dictionaries and basic file reading.
●​ Task:
1.​ Create a text file named "data.txt" with the following format (each line
represents a person):​
Name:John,Age:30,City:New York​
Name:Alice,Age:25,City:London​
Name:Bob,Age:35,City:Tokyo​

2.​ Write a Python script that reads the "data.txt" file line by line.
3.​ For each line, parse the data and create a dictionary with keys "Name", "Age",
and "City".
4.​ Store these dictionaries in a list.
5.​ Print the list of dictionaries.

Assignment 5: Modules and Error Handling


●​ Objective: To practice using built-in modules and handling exceptions.
●​ Task:
1.​ Write a script that asks the user for two numbers.
2.​ Use the math module to calculate the square root of the first number.
3.​ Attempt to divide the first number by the second number.
4.​ Use try-except blocks to handle potential ValueError (if the input is not a
number) and ZeroDivisionError.
5.​ Print appropriate error messages.
6.​ if there is no error, print the result of the division, and the square root of the
first number.

Assignment 6: Object-Oriented Programming (Basic)


●​ Objective: To introduce basic concepts of classes and objects.
●​ Task:
1.​ Create a class called "Book" with attributes "title", "author", and "pages".
2.​ Implement a constructor (__init__) to initialize these attributes.
3.​ Add a method called "display_info" that prints the book's information.
4.​ Create two instances (objects) of the "Book" class.
5.​ Call the "display_info" method for each book object.

You might also like