• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 41 pages
Other

Python programming lab programs with answers

Document preview thumbnail
Preview 4 out of 41 pages

The document contains 35 small programs from Python programming, like functions,loops,canvas,numpy,concepts in a easy way..It will be helpful for the beginners.

Content preview

Python Programming basic programs

List of Experiments:
1. Start a Python interpreter and use it as a Calculator.
2. Write a program to calculate compound interest when principal, rate and number of
periods are given.
3. Read the name, address, email and phone number of a person through the keyboard
and print the details.
4. Print the below triangle using for loop.
5
44
333
2222
11111
5. Write a program to check whether the given input is digit or lowercase character or
uppercase character or a special character(use 'if-else-if' ladder)
6. Python program to print all prime numbers in a given interval (use break)
7. Write a program to convert a list and tuple into arrays.
8. Write a program to find common values between two arrays.
9. Write a function called palindrome that takes a string argument and returnsTrue if it
is a palindrome and False otherwise. Remember that you can use the built-in
function len to check the length of a string.
10. Write a function called is_sorted that takes a list as a parameter and returns True if
the list is sorted in ascending order and False otherwise.
11. Write a function called has duplicates that takes a list and returns True if there is any
element that appears more than once. It should not modify the original list.
12. Write a function called remove duplicates that takes a list and returns a new list with
only the unique elements from the original. Hint: they don’t have to be in the same
order.
13. The wordlist I provided, words.txt, doesn’t contain single letter words. So you might
want to add “I”, “a”, and the empty string.
14. Write a python code to read dictionary values from the user. Construct a function to
invert its content. i.e., keys should be values and values should be keys.
15. Add a comma between the characters. If the given word is 'Apple', it should become
'A,p,p,l,e'
16. Remove the given word in all the places in a string?
17. Write a function that takes a sentence as an input parameter and replaces the first
letter of every word with the corresponding upper case letter and the rest of the
letters in the word by corresponding letters in lower case without using a built-in
function?
18. Writes a recursive function that generates all binary strings of n-bit length
19. Write a python program that defines a matrix and prints
20. Write a python program to perform multiplication of two square matrices

, 21. How do you make a module? Give an example of construction of a module using
different geometrical shapes and operations on them as its functions.
22. Use the structure of exception handling all general-purpose exceptions.
23. Write a function called draw_rectangle that takes a Canvas and a Rectangle as
arguments and draws a representation of the Rectangle on the Canvas.
24. Add an attribute named color to your Rectangle objects and modify draw_rectangle
so that it uses the color attribute as the fill color.
25. Write a function called draw_point that takes a Canvas and a Point as arguments and
draws a representation of the Point on the Canvas.
26. Define a new class called Circle with appropriate attributes and instantiate a few
Circle objects. Write a function called draw_circle that draws circles on the canvas.
27. Write a python code to read a phone number and email-id from the user and validate
it for correctness.
28. Write a Python code to merge two given file contents into a third file.
29. Write a Python code to open a given file and construct a function to check for given
words present in it and display on found.
30. Write a Python code to Read text from a text file, find the word with most number of
occurrences
31. Write a function that reads a file file1and displays the number of words, number of
vowels, blank spaces, lower case letters and uppercase letters.
32. Import numpy, Plotpy and Scipy and explore their functionalities.
33. Install NumPypackage with pip and explore it.
34. Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-OR
35. Write a GUI program to create a window wizard having two text labels, two
textfields and two buttons as Submit and Reset


Program Outcomes (POs)/Program Specific Outcomes (PSOs)
Course
Outcomes PO PO PO PO PO PO PO PO PO PO1 PO1 PO1 PSO PSO
1 2 3 4 5 6 7 8 9 0 1 2 1 2
CO1
CO2
CO3
CO4
CO5
Average
Correlation: 3–Strong; 2–Medium; 1-Weak


1.Start a Python interpreter and use it as a Calculator

1. Open your terminal (Command Prompt on Windows, Terminal on macOS/Linux).

, 2. Type python or python3 and press Enter:

Step 2: Perform Basic Arithmetic

At the >>> prompt, you can type arithmetic expressions:

>>> 2 + 3
5

>>> 10 - 4
6

>>> 5 * 6
30

>>>
4.0

>>> 7 // 2 # Integer division (quotient)
3

>>> 7 % 2 # Modulus (remainder)
1

>>> 2 ** 3 # Exponentiation (2^3)
8



2.Write a program to calculate compound interest when principal, rate and number of
periods are given.


# Program to calculate compound interest


# Get input from user
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the annual interest rate (in %): "))
time = float(input("Enter the time period (in years): "))
n = float(input("Enter the number of times interest is compounded per year: "))


# Calculate compound interest
amount = principal * (1 + (rate / (100 * n))) ** (n * time)

, compound_interest = amount - principal


# Display results
print(f"\nCompound Interest = {compound_interest:.2f}")
print(f"Total Amount after {time} years = {amount:.2f}")


Example Output:
Enter the principal amount: 10000
Enter the annual interest rate (in %): 5
Enter the time period (in years): 2
Enter the number of times interest is compounded per year: 4


Compound Interest = 104.08
Total Amount after 2.0 years = 10204.08


3. Read the name, address, email and phone number of a person through the
keyboard and print the details.



# Reading details from user


name = input("Enter your name: ")
address = input("Enter your address: ")
email = input("Enter your email: ")
phone = input("Enter your phone number: ")


# Displaying details
print("\n--- Person Details ---")
print("Name :", name)
print("Address:", address)
print("Email :", email)
print("Phone :", phone)

Document information

Uploaded on
August 22, 2026
Number of pages
41
Written in
2026/2027
Type
Other
Person
Unknown
$6.59

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
3
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions