Mastering Python Basics: 18 Essential Programs with Input, Conditional, and Loops
Sr. No | Topics of Programs |
Programs of print Function | |
1 | To print General Information |
2 | To Sum, Subtract, Multiply, divide of two different values |
3 | To print a simple table of number 7 |
4 | To convert value from meter to centimeter |
Programs of Input Function | |
5 | To calculate percentage of different 5 subjects |
6 | To calculate area of circle |
7 | To interchange two different values |
8 | To calculate area of triangle with base and height |
Programs of list | |
9 | Create a list in python of ranker students with the following names- Tanmay, Khushi, Vrinda, Ananya, Tushar Perform the following tasks on the list in sequence 1. Print the whole list 2. Add the name Rudra at the end 3. Delete the name Khushi from the list 4. Remove the name which is at the fourth position |
10 | Create a list no[13, 15, 8, 90,55, 28] 1. Print the length of list 2. Print the elements from 1st to 3rd position (With positive indexing) |
11 | Create a list of the first 10 even numbers, add 1 into each list item, and print the final list. |
12 | Create a list list_1 [11, 21, 13, 14]. Add the elements [15, 17, 25] using the extend function. Now sort the final list in ascending order and print it. |
Program of Conditional, Iterative Statements | |
13 | Program to check the grade of student |
14 | Program to check if the number is positive, negative or zero |
15 | Program to print first 10 even numbers |
16 | Program to print odd numbers from 1 to n |
17 | Program to print sum of first 10 natural numbers |
18 | Program to find the sum of all given numbers and sorted in a list |
Here, i will provide the solution of this above all programs.
- Program to print general information like Hello and student name.
print(“Message – Hello”)
print(“Student Name – Tanmay Patel”)
2. Program to calculate Sum, Subtract, Multiply, divide of two different values.
#Addition
num1 = int(input(“Enter first number: “))
num2 = int(input(“Enter second number: “))
sum = num1 + num2
print(“Sum:”, sum)
#Subtraction
num1 = int(input(“Enter first number: “))
num2 = int(input(“Enter second number: “))
difference = num1 – num2
print(“Difference:”, difference)
#Multiplication
num1 = int(input(“Enter first number: “))
num2 = int(input(“Enter second number: “))
product = num1 * num2
print(“Product:”, product)
#Division
num1 = int(input(“Enter first number: “))
num2 = int(input(“Enter second number: “))
quotient = num1 / num2
print(“Quotient:”, quotient)
Buy the best Book to learn Python is “Head First Python – 3rd Edition, By Paul Barry”
3. Program to print a simple table of number 7.
#Printing a table of the number 7
no = 7
print(“Multiplication Table of”, no)
print(“—————————“)
for i in range(1, 11):
print(no, “x”, i, “=”, no * i)
4. Program to convert value from meter to centimeter
#Convert value from meters to centimeters
meters = float(input(“Enter value in meters: “))
centimeters = meters * 100
print(“Value in centimeters:”, centimeters)
5. To calculate percentage of different 5 subjects
Oracle=int(input(“Enter marks of Oracle:”))
C=int(input(“Enter marks of C:”))
CPP=int(input(“Enter marks of CPP:”))
HTML=int(input(“Enter marks of HTML:”))
PHP=int(input(“Enter marks of PHP:”))
total=Oracle+C+CPP+HTML+PHP
per=total/5
print(“percentage of 5 subjects marks:”, per)
6. Program to calculate area of circle
import math
radius = float(input(“Enter the radius of the circle: “))
area = math.pi * radius ** 2
print(“The area of the circle with radius”, radius, “is:”, area)
7. Program to interchange two different values
a = int(input(“Enter value of a: “))
b = int(input(“Enter value of b:”))
temp = a
a = b
b = temp
print(“a =”, a)
print(“b =”, b)
8. Program to calculate area of triangle with base and height
Base=float(input(“Enter base:”))
Height=float(input(“Enter height:”))
area=Base*Height/2
print(“Area of triangle:”, area)
9. Create a list in python of ranker students with the following names- Tanmay, Khushi, Vrinda, Ananya, Tushar. Perform the following tasks on the list in sequence
- Print the whole list
- Add the name Rudra at the end
- Delete the name Khushi from the list
- Remove the name which is at the fourth position
stu_lst=[‘Tanmay’,’Khushi’,’Vrinda’,’Ananya’,’Tushar’]
#Print the whole list
print(stu_lst)
#Add the name Rudra at the end
stu_lst.append(‘Rudra’)
#Delete the name Khushi
#method – 1
del stu_lst[‘Khushi’]
#Method – 2
stu_lst.pop(stu_lst.index(‘Khushi’))
#remove the item at Fourth position
stu_lst.remove(stu_lst[4]) print(stu_lst)
10. Create a list no[13, 15, 8, 90,55, 28]
- Print the length of list
- Print the elements from 1st to 3rd position (With positive indexing)
no=[13,15,8,90,55,28]
#printing the length of the list
print(“Length of list is:”, len(num))
#Print the elements from first to third position (With positive indexing)
print(“1st to 3rd Position elements:”,num[1:3])
11. Create a list of the first 10 even numbers, add 1 into each list item, and print the final list.
l=list(range(2,21,2))
print(l)
for i in range(len(l)):
l[i]=l[i]+1
print(l)
12. Create a list list_1 [11, 21, 13, 14]. Add the elements [15, 17, 25] using the extend function. Now sort the final list in ascending order and print it.
list_1=[11,21,13,14]
list_1.extend([15,17,25])
list_1.sort()
print(list_1)
13. Program to check the grade of student
per=float(input(“Enter Percentage:”))
if per>=91 and per<=100:
print(“Grade: A”)
elif per>=71 and per<=90:
print(“Grade: B”)
elif per>=51 and per<=70:
print(“Grade: C”)
elif per>=35 and per<=50:
print(“Grade: D”)
else:
print(“Imrovemenet required…”)
14. Program to check if the number is positive, negative or zero
n=int(input(“Enter any number to check:”))
if n>0:
print(“No is positive”)
elif n<0:
print(“No is negative”)
else:
print(“Zero”)
15. Program to print first 10 even numbers
for i in range(1,21,2):
print(i)
16. Program to print odd numbers from 1 to n.
for i in range(1,21,2):
print(i)
17. Program to print sum of first 10 natural numbers.
s=0
for i in range(1,11):
s+=i
print(s)
18. Program to find the sum of all numbers sorted in a list.
l=[10,20,30,40,50]
s=0
for i in l:
s+=i
print(s)