0% found this document useful (0 votes)
3 views

Python_Practice_Programs (1)

The document outlines a comprehensive Python syllabus covering various topics including introduction to Python, program flow control, complex data types, functions, file operations, packages, GUI programming, and IDE usage. Each section includes specific programming exercises to enhance practical understanding. The syllabus is designed for learners to progressively build their Python skills through structured lessons and hands-on practice.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python_Practice_Programs (1)

The document outlines a comprehensive Python syllabus covering various topics including introduction to Python, program flow control, complex data types, functions, file operations, packages, GUI programming, and IDE usage. Each section includes specific programming exercises to enhance practical understanding. The syllabus is designed for learners to progressively build their Python skills through structured lessons and hands-on practice.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Python Syllabus

1. Introduction to Python
• Python variables
• Python basic operators
• Understanding Python blocks
• Python data types
o Declaring and using numeric data types: int, float, etc.
S.no. Program
1 Declare a variable age and assign the value 25. Print the variable and its data type.
2 Swap the values of two variables x = 10 and y = 20 without using a third variable.
3 Declare a variable var and assign the value 10 to it. Later change the value of var to 10.5 and
then to "Hello". Print the variable and its type after each assignment.
4 Assign the same value 5 to three variables a, b, and c. Print them.
5 Assign the values 1, 2, 3 to variables x, y, and z in a single line and print their sum.
6 Write a program to input two numbers and print their sum, difference, product, and division.
7 If x = 20, y = 3, compute and print x // y, x % y, and x ** y.
8 Write a program that checks if a number is both greater than 10 and less than 20 using logical
operators.
9 Given x = 5 and y = 10, use the and, or, and not operators to compare their values and print
the results.
10 Write a Python program that takes input from the user for their name, age, and weight (as
float). Then, print a formatted string that says, "Your name is namenamename, age is
ageageage and weight is weightweightweight kg."

2. Python Program Flow Control


• Conditional blocks:
o if, else, and elif
• Loops:
o Simple for loops
o for loop using ranges, strings, lists, and dictionaries
o while loops
• Loop manipulation:
o pass, continue, break, and else
• Programming using Python conditional and loop blocks

S.no. Program
1 Write a program to check if a number is positive, negative, or zero. Use proper indentation to
define blocks for if, elif, and else.
2 Input the user's age and print whether they are eligible to vote (18 or older) or not.
3 Write a program to input a student's score and print the grade based on the following rules:
• 90 and above: A
• 80-89: B
• 70-79: C
• 60-69: D
• Below 60: F
4 Print the first 5 multiples of a given number using a for loop.
5 Write a program to print the squares of numbers from 1 to 10 using a for loop with range().
6 Given a string name = "Computer Science and Engineering", count and print the number of
vowels in the string using a for loop.
7 Write a program to keep asking the user for a number and find the sum of all numbers entered.
Stop when the user inputs 0.
8 Write a program that iterates through numbers 1 to 10 using a for loop and prints each
number, but use the pass statement for numbers divisible by 3.
9 Modify the program to print numbers between 1 and 20 that are not multiples of 3, using
continue.
10 Write a Python program where the user has to guess a randomly generated number between 1
and 100. Give feedback on whether the guess is too high or too low, and let the user keep
guessing until they find the correct number.

3. Python Complex Data Types


• Using string data type and string operations
• Defining lists and list slicing
• Use of tuple data type
• String, list, and dictionary manipulations:
o String manipulation methods
o List manipulation
o Dictionary manipulation
• Programming using string, list, and dictionary in-built functions
S.no. Program
1 Write a program that iterates over a dictionary of student names and their marks, printing each
student's name and marks.
2 Given a list of fruits fruits = ["apple", "banana", "cherry"], print each fruit using a for loop.
3 Given two tuples (1, 2, 3) and (4, 5, 6), concatenate them and print the result.
4 Write a program to replace all spaces in a string with hyphens using replace().
5 Write a Python program to add a new key-value pair to a dictionary and update the value of an
existing key using update().
6 Write a Python program to find the key with the highest value in the dictionary scores =
{"Alice": 85, "Bob": 90, "Charlie": 88}.
7 Write a Python program that takes a string as input and counts the frequency of each word in
the string using a dictionary.
8 Write a program that inputs a list of numbers and prints a new list with only the unique
elements.
9 Write a Python program that takes a string, converts it into a list of characters, reverses the
list, and then joins it back into a string to print the reversed string.
10 Write a Python program to store student information (name, age, course) using a dictionary,
and allow the user to input the details of multiple students. Later, print the details of each
student.

4. Python Functions
• Organizing Python codes using functions

S.no. Program
1 Write a Python function fibonacci(n) that returns the nth Fibonacci number using recursion.
Test the function with different values of n.
2 Write a lambda function that takes two numbers as input and returns their sum.
3 Write a Python program that demonstrates the difference between a local and a global
variable. Declare a global variable x = 10, then modify it locally inside a function and print
the results before and after the function call.
4 Write a Python program to create a simple calculator that can add, subtract, multiply, and
divide using functions. Each operation should be a separate function.
5 Write a function is_prime(n) that checks if a number is prime. Use this function inside a
program to check if a given number is prime or not.
6 Write a function is_palindrome(s) that checks if a given string s is a palindrome (reads the
same forward and backward). Use this function inside a program to check different strings.
7 Write a Python function find_largest(lst) that takes a list of numbers as input and returns the
largest number.
8 Write a function celsius_to_fahrenheit(celsius) that converts Celsius to Fahrenheit and another
function fahrenheit_to_celsius(fahrenheit) that converts Fahrenheit to Celsius. Use these
functions in a program to perform the conversions.
9 Write a function count_words(sentence) that takes a sentence as input and returns the number
of words in it.
10 Write a function validate_password(password) that checks if a password meets the following
criteria:
• At least 8 characters long
• Contains both uppercase and lowercase characters
• Contains at least one number Use this function inside a program to validate user-
entered passwords.

5. Python File Operations


• Reading files:
o read(), readline(), readlines()
• Writing files:
o write() and writelines()
• Manipulating file pointer using seek
• Programming using file operations
S.no. Program
1 Write a Python program that reads and prints each line of a file one by one using readline() in
a loop.
2 Write a program that appends "This is a new line." to an existing file using the write() method.
3 Write a Python program that reads the first 10 characters of a file, then uses seek(5) to move
the pointer to the 6th character, and reads the next 5 characters from that position.
4 Write a Python program that reads a text file and counts the number of words, lines, and
characters in the file.
5 Write a Python program that takes user input and appends it to a file. The program should
continue accepting input until the user enters "STOP".
6 Write a Python program that writes a list of dictionaries (containing student data like name,
age, and grade) to a CSV file.
7 Write a Python program that compares the contents of two files line by line and reports any
differences.
8 Write a Python program that reads the contents of a file and writes the lines in reverse order to
a new file (i.e., last line first, first line last).
9 Write a program that reads a file and replaces all occurrences of a given word with another
word, saving the changes to the file.
10 Write a Python program that reads a file and counts how many times a specific word appears
in the file.

6. Python Packages
• Using built-in functions of packages:
o matplotlib
o numpy
o pandas
S.no. Program
1 Plot a graph of y = x^2 for x values from 0 to 10. Customize the graph with the following
features:
• Set the title as "Quadratic Function"
• Label the x-axis as "x" and the y-axis as "y"
• Change the line color to red and line style to dashed.
2 Given the list of students' names ["Alice", "Bob", "Charlie", "David"] and their corresponding
scores [85, 92, 78, 90], plot a bar chart to represent the scores of each student.
3 Write a Python program that generates random x and y data points using numpy and creates a
scatter plot using matplotlib.
4 Write a Python program that multiplies two 3x3 matrices using numpy’s dot() function.
5 Create a numpy array with numbers from 1 to 20 and slice the array to print:
• The first 5 elements
• The last 5 elements
• Elements at even indices
6 Create two numpy arrays a = np.array([1, 2, 3]) and b = np.array([4, 5, 6]). Perform element-
wise addition, subtraction, multiplication, and division of these arrays and print the results.
7 Given a numpy array data = np.array([10, 15, 7, 22, 17]), calculate and print the following
statistics:
• Mean
• Standard deviation
• Median
• Sum of all elements
8 Create a DataFrame with the following data:

data = {"Name": ["John", "Anna", "Peter", "Linda"],


"Age": [28, 24, 35, 32],
"City": ["New York", "London", "Berlin", "Tokyo"]}
Perform the following operations:
• Print the column "Age".
• Add a new column "Salary" with values [50000, 60000, 55000, 65000].
• Filter and display rows where the "Age" is greater than 30.
9 Write a Python program to merge two DataFrames using pandas. One DataFrame contains
employee details (ID, Name, Department), and another contains employee salaries (ID,
Salary). Merge them based on the "ID" column.
10 Read a CSV file containing daily weather data (e.g., temperature, humidity, rainfall). Use
pandas to perform the following:
• Calculate the average temperature for each month.
• Plot a line graph of the daily temperature over time using matplotlib.

7. GUI Programming
• Tkinter introduction
• Tkinter and Python programming
• Tk widgets and examples
S.no. Program
1 Write a Python program to create a basic Tkinter window with the following properties:
• The window title should be "Welcome Window".
• The window should have a fixed size of 500x400 pixels.
• Add a label that says "Hello, Tkinter!" in the center of the window.
Objective: Understand how to create a basic Tkinter window, set window properties, and add
a label widget.
2 Create a Tkinter window with a button labeled "Press Me". When the button is clicked, it
should display a pop-up message box with the text "Button was clicked!".
Objective: Learn how to create buttons and handle events (button clicks) with the command
option and message boxes.
3 Build a simple calculator using Tkinter. The calculator should have buttons for numbers 0-9,
and basic arithmetic operators (+, -, *, /). It should display the result when the user clicks the
"=" button.
Objective: Combine multiple widgets (buttons, labels, and entry boxes) to create a simple
application, and learn about handling input and calculations in Tkinter.
4 Create a login form with two input fields for username and password. Add a "Login" button
that validates the inputs:
• If the username is "admin" and the password is "password123", display "Login
successful" in a label below the button.
• If the credentials are incorrect, display "Invalid username or password".
Objective: Learn about entry widgets, buttons, and basic form validation using Python logic
within a Tkinter application.
5 Create a Tkinter application to convert temperatures between Celsius and Fahrenheit. It
should have:
• Two entry fields: one for Celsius and one for Fahrenheit.
• Buttons to convert from Celsius to Fahrenheit and vice versa.
• Display the converted temperature in the appropriate entry field.
Objective: Practice handling user input and output, as well as using Tkinter's entry boxes and
buttons to build a useful tool.

8. Python Programming with IDE


• Using an Integrated Development Environment (IDE) for Python programming
1. PyCharm
• Description: One of the most widely used Python IDEs, developed by JetBrains. PyCharm offers
a powerful set of tools for Python development, including intelligent code completion,
debugging, testing, and support for web development frameworks.
• Key Features:
o Intelligent code editor with code suggestions.
o Integrated debugger and test runner.
o Version control integration (Git, SVN, etc.).
o Support for Django and Flask frameworks.
o Community (free) and Professional (paid) editions.
2. Spyder
• Description: A popular open-source IDE designed specifically for data science and scientific
computing with Python. It comes packaged with Anaconda, making it an ideal choice for data
analysis and machine learning tasks.
• Key Features:
o Integrated with scientific libraries like NumPy, SciPy, and Matplotlib.
o Variable explorer for inspecting variables and data.
o Interactive IPython console for real-time code execution.
o Built-in support for data visualization.
3. Jupyter Notebook
• Description: Not exactly an IDE, but a popular interactive environment for writing Python code
in notebook format. It’s widely used for data science, machine learning, and teaching, where users
can combine code, text, and visualizations in a single document.
• Key Features:
o Supports live code execution, markdown, and visualizations in the same document.
o Integration with scientific Python libraries (NumPy, pandas, Matplotlib, etc.).
o Great for teaching, prototyping, and exploratory data analysis.
o Supports kernels for multiple languages, including Python, R, and Julia.
• Best For: Data science, teaching, prototyping, and data visualization.
4. IDLE
• Description: IDLE (Integrated Development and Learning Environment) is the default IDE that
comes bundled with Python. It is lightweight, easy to use, and provides a simple environment for
beginners.
• Key Features:
o Comes pre-installed with Python, so no setup required.
o Lightweight and simple interface.
o Supports syntax highlighting, basic debugging, and interactive shell.
o Suitable for small projects and quick scripts.

You might also like