Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Basic Program of Python Part-I

Uploaded by

shantha.merlion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Basic Program of Python Part-I

Uploaded by

shantha.merlion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Question 1:- Program to find sum of two Numbers

n1=int(input("Enter first Number:-"))


n2=int(input("Enter Second Number:-"))
add=n1+n2
print(f"Sum of {n1} + {n2} = {add}")

Enter first Number:- 5


Enter Second Number:- 10

Sum of 5 + 10 = 15

Question 2:- Program to find area and circumference of circle.(area=Pi * r * r and Circumfrence=2 * pi * r)

r=int(input("Enter the radious:-"))


area=3.14*r*r
cir=2*3.14*r
print(f"Area of Circle = {area} .")
print(f"Circumfrence of circle = {cir} .")

Enter the radious:- 5

Area of Circle = 78.5 .


Circumfrence of circle = 31.400000000000002 .

Question 3:- Program to find Simple Interest. ( SI=(Principal Amount * Rate of Interst * time)/100)

p=int(input("Enter the Principal Amount:-"))


r=int(input("Enter the Rate of Interst:-"))
t=int(input("Enter the Time:-"))

SI=(p*r*t)/100
print(f"Simple Interst = {SI} .")
Enter the Principal Amount:- 10000
Enter the Rate of Interst:- 5
Enter the Time:- 2

Simple Interst = 1000.0 .

Question 4:- Program to convert temperature from degree centigrade to Fahrenheit.(f=(1.8 * c ) + 32)

c=float(input("Enter Degree in Centigrade:-"))


f=(1.8 * c)+32
print(f"{c} Degree Centigrade = {f} Degree Fahrenheit. ")

Enter Degree in Centigrade:- 32

32.0 Degree Centigrade = 89.6 Degree Fahrenheit.

Question 5:- Program to calculate sum of 5 subject and find percentage.

name=input("Enter Student Name:-")


n=int(input("Enter Number of Subject:-"))
m=n
mark_name={}
for i in range(1,n+1):
sub_name=input(f"Enter {i} Subject Name:-")
marks=float(input("Enter Marks:-"))
mark_name[sub_name]=marks
add=0
for j in mark_name:
add=add+mark_name[j]

print(f"Student Name is - {name} .")


print("Subject Name Marks")
for key, value in mark_name.items():
print(f"{key} {value}")
print("Total Marks:-", add)
print("Percentage is :-",add/m)

Enter Student Name:- Sushil Kushwaha


Enter Number of Subject:- 5
Enter 1 Subject Name:- Hindi
Enter Marks:- 78
Enter 2 Subject Name:- English
Enter Marks:- 69
Enter 3 Subject Name:- Mathe
Enter Marks:- 87
Enter 4 Subject Name:- Physices
Enter Marks:- 69
Enter 5 Subject Name:- Chemistry
Enter Marks:- 87

Student Name is - Sushil Kushwaha .


Subject Name Marks
Hindi 78.0
English 69.0
Mathe 87.0
Physices 69.0
Chemistry 87.0
Total Marks:- 390.0
Percentage is :- 78.0

Question 6:-Program to Reverse a given number.

n=int(input("Enter More Than Two Digit Number:-"))


m=n
s=0
while n>0:
rem=n%10
s=s*10+rem
n=n//10

print(f"Reverse of {m} is - {s}")

Enter More Than Two Digit Number:- 12345

Reverse of 12345 is - 54321

Question 7:-Program to show swap of two Number without using third variable.

num1=int(input("Enter First Number:-"))


num2=int(input("Enter Second Number:-"))

print(f"Before swapping: num1 = {num1}, num2 = {num2}")

num1, num2 = num2, num1

print(f"After swapping: num1 = {num1}, num2 = {num2}")

Enter First Number:- 6


Enter Second Number:- 4

Before swapping: num1 = 6, num2 = 4


After swapping: num1 = 4, num2 = 6

Question 8:- Program to find gross salary. (da,ta,hra,)

bs=float(input("Enter Your Base Salary:-"))


ta=float(input("Enter Your TA:-"))
da=float(input("Enter Your DA:-"))
hra=float(input("Enter Your HRA:-"))
DA=bs*da/100
TA=bs*ta/100
HRA=bs*hra/100
gs=DA+TA+HRA+bs
print("Summary of Your Salary:-")
print("Bass Salary:-",bs)
print(f"{ta} % of Your TA is:- {TA} ")
print(f"{da} % of Your TA is:- {DA} ")
print(f"{hra} % of Your TA is:- {HRA} ")
print("Your Gross Salary:-",gs)

Enter Your Base Salary:- 10000


Enter Your TA:- 10
Enter Your DA:- 5
Enter Your HRA:- 25

Summary of Your Salary:-


Bass Salary:- 10000.0
10.0 % of Your TA is:- 1000.0
5.0 % of Your TA is:- 500.0
25.0 % of Your TA is:- 2500.0
Your Gross Salary:- 14000.0

Question 9(a):- Program to print a Table of any number.

n=int(input("Enter the Number, You want to print Table:-"))


for i in range(1,11):
tab=i*n
print(tab)

Enter the Number, You want to print Table:- 10

10
20
30
40
50
60
70
80
90
100

Question 9(b):- Program to print a Table from 1 to n number.

n=int(input("Enter the Number:-"))


for i in range(1,11):
for j in range(1,n+1):
print(f"{i} X {j} ={i*j}" , end="\t")
print("")

Enter the Number:- 5

1 X 1 =1 1 X 2 =2 1 X 3 =3 1 X 4 =4 1 X 5 =5
2 X 1 =2 2 X 2 =4 2 X 3 =6 2 X 4 =8 2 X 5 =10
3 X 1 =3 3 X 2 =6 3 X 3 =9 3 X 4 =12 3 X 5 =15
4 X 1 =4 4 X 2 =8 4 X 3 =12 4 X 4 =16 4 X 5 =20
5 X 1 =5 5 X 2 =10 5 X 3 =15 5 X 4 =20 5 X 5 =25
6 X 1 =6 6 X 2 =12 6 X 3 =18 6 X 4 =24 6 X 5 =30
7 X 1 =7 7 X 2 =14 7 X 3 =21 7 X 4 =28 7 X 5 =35
8 X 1 =8 8 X 2 =16 8 X 3 =24 8 X 4 =32 8 X 5 =40
9 X 1 =9 9 X 2 =18 9 X 3 =27 9 X 4 =36 9 X 5 =45
10 X 1 =10 10 X 2 =20 10 X 3 =30 10 X 4 =40 10 X 5 =50

Question 10:- Program to find Greatest in 3 number.

num1=int(input("Enter First Number:-"))


num2=int(input("Enter Second Number:-"))
num3=int(input("Enter third Number:-"))

if num1>num2 and num1>num3:


print(f"{num1} is greatest.")
elif num2>num1 and num2>num3:
print(f"{num2} is greatest.")
else:
print(f"{num3} is greatest.")

Enter First Number:- 5


Enter Second Number:- 6
Enter third Number:- 2

6 is greatest.

Question 11:- Program to show the use of conditional operator.

num1=int(input("Enter First Number:-"))


num2=int(input("Enter Second Number:-"))

Max_value= num1 if num1>num2 else num2


print(f"The Largest Number between {num1} and {num2} is {Max_value}")

Enter First Number:- 6


Enter Second Number:- 9

The Largest Number between 6 and 9 is 9

Question 12:- Program to find that entered year is leap year or not.

year=int(input("Enter the year:-"))


if year%400==0:
print("This is leap Year")
elif year%4==0:
print("This is Leap Year")
elif year%100==0:
print("This is Leap Year")
else:
print("This Is Not Leap year")

Enter the year:- 2025


This Is Not Leap year

Question 13:- Program to find whether given number is even or odd.

num1=int(input("Enter Number:-"))
if num1%2==0:
print(f"Number {num1} is Even")
else:
print(f"Number {num1} is Odd")

Enter Number:- 5

Number 5 is Odd

Question 14:- Program to shift inputed data by two bits to left.

num1=int(input("Enter Number:-"))

left_shift= num1<<2
right_shift=num1>>2

print(f"The result of Shifting {num1} by two bits to the left is {left_shift} ")
print(f"The result of Shifting {num1} by two bits to the right is {right_shift} ")

Enter Number:- 5

The result of Shifting 5 by two bits to the left is 20


The result of Shifting 5 by two bits to the right is 1

Question 15:- Program to use switch statement. display monday to sunday.

# Python doesn’t have a direct switch statement like some other languages

def display_days(day_number):
days = {
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
7: "Sunday"
}

if day_number in days:
print(f"Day {day_number}: {days[day_number]}")
else:
print("Invalid day number. Please enter a number between 1 and 7.")

day_number = int(input("Enter a day number (1-7): "))


display_days(day_number)

Enter a day number (1-7): 5

Day 5: Friday

Question 16:-Program to display arithmatic operater using switch case.

# Python doesn’t have a direct switch statement like some other languages

def arithmetic_operation(operator, num1, num2):


if operator == '+':
return num1 + num2
elif operator == '-':
return num1 - num2
elif operator == '*':
return num1 * num2
elif operator == '/':
if num2 != 0:
return num1 / num2
else:
return "Error: Division by zero"
else:
return "Invalid operator"

operator = input("Enter an arithmetic operator (+, -, *, /): ")


num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
result = arithmetic_operation(operator, num1, num2)
print(f"{num1} {operator} {num2} = {result}")

Enter an arithmetic operator (+, -, *, /): +


Enter the first number: 56
Enter the second number: 43

56 + 43 = 99

Question 17:- Program to display first 10 natural number and their sum.

sum=0
print("This is First 10 Natural Number")
for i in range(1,11):
sum=sum+i
print(i)

print("This is Sum of First 10 Natural Number:-",sum)

This is First 10 Natural Number


1
2
3
4
5
6
7
8
9
10
This is Sum of First 10 Natural Number:- 55

Question 18:- Program to print stars sequence 1.

n=int(input("Enter Number,You want to print Stars:-"))


for i in range(1,n+1):
for j in range(i):
print("*", end="")
print("")

Enter Number,You want to print Stars:- 5

*
**
***
****
*****

Question 19:- Program to print stars sequence 2.

n=int(input("Enter Number:-"))
for i in range(1,n+1):
for j in range(i):
print(i, end="")
print("")
Question 20:- Program to print stars sequence 3.

n=int(input("Enter Number,You want to print Stars:-"))


for i in range(n,0,-1):
for j in range(1,i+1):
print(j, end="")
print("")

12345
1234
123
12
1

You might also like