Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

140+ python programs

Rating
-
Sold
-
Pages
96
Uploaded on
13-03-2025
Written in
2024/2025

This is best resource to prepare for your interview or semister exams, this is very simple and easy to understand.

Institution
Course

Content preview

140+
Basic
Python
Programs
This resource can assist you in
preparing for your interview




Piush Kumar Sharma

,11/26/23, 4:53 AM Basic Python Program - Jupyter Notebook




Program 1

Write a Python program to print "Hello Python".

In [1]: 1 print("Hello Python")

Hello Python



Program 2

Write a Python program to do arithmetical operations addition and division.

In [2]: 1 # Addition
2 num1 = float(input("Enter the first number for addition: "))
3 num2 = float(input("Enter the second number for addition: "))
4 sum_result = num1 + num2
5 print(f"sum: {num1} + {num2} = {sum_result}")

Enter the first number for addition: 5
Enter the second number for addition: 6
sum: 5.0 + 6.0 = 11.0


In [3]: 1 # Division
2 num3 = float(input("Enter the dividend for division: "))
3 num4 = float(input("Enter the divisor for division: "))
4 if num4 == 0:
5 print("Error: Division by zero is not allowed.")
6 else:
7 div_result = num3 / num4
8 print(f"Division: {num3} / {num4} = {div_result}")

Enter the dividend for division: 25
Enter the divisor for division: 5
Division: 25..0 = 5.0



Program 3

Write a Python program to find the area of a triangle.

In [4]: 1 # Input the base and height from the user
2 base = float(input("Enter the length of the base of the triangle: "))
3 height = float(input("Enter the height of the triangle: "))
4 # Calculate the area of the triangle
5 area = 0.5 * base * height
6 # Display the result
7 print(f"The area of the triangle is: {area}")

Enter the length of the base of the triangle: 10
Enter the height of the triangle: 15
The area of the triangle is: 75.0


localhost:8888/notebooks/Piush Kumar Sharma/Basic Python Program.ipynb 1/95

,11/26/23, 4:53 AM Basic Python Program - Jupyter Notebook



Program 4

Write a Python program to swap two variables.

In [5]: 1 # Input two variables
2 a = input("Enter the value of the first variable (a): ")
3 b = input("Enter the value of the second variable (b): ")
4 # Display the original values
5 print(f"Original values: a = {a}, b = {b}")
6 # Swap the values using a temporary variable
7 temp = a
8 a = b
9 b = temp
10 # Display the swapped values
11 print(f"Swapped values: a = {a}, b = {b}")

Enter the value of the first variable (a): 5
Enter the value of the second variable (b): 9
Original values: a = 5, b = 9
Swapped values: a = 9, b = 5



Program 5

Write a Python program to generate a random number.

In [6]: 1 import random
2 print(f"Random number: {random.randint(1, 100)}")

Random number: 89



Program 6

Write a Python program to convert kilometers to miles.

In [7]: 1 kilometers = float(input("Enter distance in kilometers: "))
2 ​
3 # Conversion factor: 1 kilometer = 0.621371 miles
4 conversion_factor = 0.621371
5 ​
6 miles = kilometers * conversion_factor
7 ​
8 print(f"{kilometers} kilometers is equal to {miles} miles")

Enter distance in kilometers: 100
100.0 kilometers is equal to 62.137100000000004 miles



Program 7

Write a Python program to convert Celsius to Fahrenheit.



localhost:8888/notebooks/Piush Kumar Sharma/Basic Python Program.ipynb 2/95

, 11/26/23, 4:53 AM Basic Python Program - Jupyter Notebook


In [8]: 1 celsius = float(input("Enter temperature in Celsius: "))
2 ​
3 # Conversion formula: Fahrenheit = (Celsius * 9/5) + 32
4 fahrenheit = (celsius * 9/5) + 32
5 ​
6 print(f"{celsius} degrees Celsius is equal to {fahrenheit} degrees Fahr

Enter temperature in Celsius: 37
37.0 degrees Celsius is equal to 98.6 degrees Fahrenheit



Program 8

Write a Python program to display calendar.

In [9]: 1 import calendar
2 ​
3 year = int(input("Enter year: "))
4 month = int(input("Enter month: "))
5 ​
6 cal = calendar.month(year, month)
7 print(cal)

Enter year: 2023
Enter month: 11
November 2023
Mo Tu We Th Fr Sa Su
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30




Program 9

Write a Python program to solve quadratic equation.


The standard form of a quadratic equation is:

𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
where

a, b and c are real numbers and

𝑎≠0
The solutions of this quadratic equation is given by:

(−𝑏 ± (𝑏2 − 4𝑎𝑐)1/2)/(2𝑎)


localhost:8888/notebooks/Piush Kumar Sharma/Basic Python Program.ipynb 3/95

Written for

Institution
Course

Document information

Uploaded on
March 13, 2025
Number of pages
96
Written in
2024/2025
Type
OTHER
Person
Unknown

Subjects

$6.99
Get access to the full document:

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

Get to know the seller
Seller avatar
safiyanaguri

Get to know the seller

Seller avatar
safiyanaguri Mohan Babu University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

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