100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Python notes 150

Rating
-
Sold
-
Pages
96
Uploaded on
04-12-2024
Written in
2023/2024

**Python 150 Programming Notes by Piush Kumar Sharma** is a comprehensive guide designed for both beginners and experienced programmers. It offers 150 carefully selected programming problems, complete with detailed solutions and explanations. Each problem is structured to enhance your understanding of core Python concepts, including data structures, algorithms, file handling, object-oriented programming, and more. The book is divided into sections that cater to various difficulty levels, making it an excellent resource for those preparing for coding interviews, competitive programming, or simply looking to improve their Python skills. Additionally, the practice exercises help reinforce concepts and encourage hands-on learning. Key features include: - **150 Diverse Programming Problems**: Covers a wide range of topics to ensure well-rounded learning. - **Step-by-Step Solutions**: Clear and concise solutions to help you grasp problem-solving techniques. - **Practice Exercises**: Additional problems to test your knowledge and application skills. - **Beginner to Advanced Topics**: Suitable for all skill levels, from those new to Python to seasoned coders. This book serves as an indispensable resource for anyone aiming to master Python programming effectively and efficiently.

Show more Read less
Institution
Course











Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Course

Document information

Uploaded on
December 4, 2024
Number of pages
96
Written in
2023/2024
Type
Class notes
Professor(s)
Piush kumar sharma
Contains
All classes

Subjects

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
R137,55
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
mailtoganeshbehera

Get to know the seller

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

0,0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

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

Student with book image

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

Alisha Student

Frequently asked questions