0% found this document useful (0 votes)
5 views

Chapter 6 Basic Python Programs

Chapter 6 provides a collection of basic Python programs covering fundamental operations such as addition, maximum value determination, area and perimeter calculations for various shapes, and conditional statements. It includes examples for user input, mathematical operations, and simple algorithms to manipulate numbers and strings. The chapter serves as a practical guide for beginners to understand basic programming concepts in Python.

Uploaded by

Aarna Bhura
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chapter 6 Basic Python Programs

Chapter 6 provides a collection of basic Python programs covering fundamental operations such as addition, maximum value determination, area and perimeter calculations for various shapes, and conditional statements. It includes examples for user input, mathematical operations, and simple algorithms to manipulate numbers and strings. The chapter serves as a practical guide for beginners to understand basic programming concepts in Python.

Uploaded by

Aarna Bhura
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 6 : Basic Python Programs

1. Program to Add two numbers

# Program to add two numbers.

A= input (“Enter the First Number : ”)

B= input (“Enter the Second Number : ”)

Sum = A+B

Print (‘The sum of numbers is ‘ , Sum)

2. Program to print
My Name is Ruhaan
My Name is ‘Ruhaan’
My Name is “Ruhaan”

# Program 1: Print “ Hello Ruhaan”

Print (“ My Name is Ruhaan”)

Print (“ My Name is \‘Ruhaan\’’)

Print (“ My Name is \“Ruhaan\””)

3. Program to Find maximum of two numbers.

# Program to find maximum of two numbers in Python

A = input (“ Enter the first number:”)

B = input (“ Enter the second number:”)

If A>B :

Print (“ A is greater than B’)

Else :

Print (“ B is greater than A’)

4. Program to find Area and Perimeter of a rectangle


# Program to find Area and Perimeter of a rectangle

Length = input (‘ Enter the rectangle Length : ‘)

Breadth = input (‘Enter the rectangle Breadth : ‘)

Area = Length * Breadth


Perim = 2* (Length + Breadth)
Print (“The Area of the rectangle is :”, Area)
Print (“The perimeter of the rectangle is :”, Perim)

5. Program to find the area and perimeter of square

# Program to find the area and perimeter of square

Side = input (“Enter the side of a square : ”)

Area = Side * Side

Perim = 4 * Side

Print (“ The area of the square is : ‘ , Area)

Print (“ The perimeter of the square is : ‘ , Perim)

6. Program to find the area and perimeter of a circle.

# Program to find the area and perimeter of a circle.

R = input (“ Radius of the Circle: “)

Pi = 3.14

Circum = 2* Pi * R

Area = Pi * R * R

Print (“ The area of the circle is : ‘ , Area)

Print (“ The perimeter of the circle is : ‘ , Circum)


IF program example.

7. Write a program to print adult if age is greater than or equal to 18 otherwise not an adult.
Accept age from user

8. Write a program to print the square if the number entered is even, otherwise print its cube.

Algo

Step 1: program statement

2: input number

3: if (number % 2 == 0)

print(“The square of the number is”, number** 2 )

else

print(“The cube of the number is”, number** 3 )

9. Write a program to accept the 2 sides of a rectangle and display if its area is greater than its
perimeter.

10. Write a program to Input two numbers and a choice from a user. The program should
display the calculated result after performing the required mathematical operation
depending on the choice.
1. A+B
2. A-B
3. A/B
4. A*B

11. WAP to accept basic salary and grade from user. Calculate and display net salary

if grade = ‘A’ - HRA=12% of basic, DA= 8% of basic, allow=500, pf = 10% of basic

if grade = ‘B’ - Hra=11% of basic da= 6% of basic, allow=300, pf = 10% of basic

if grade = ‘C’ - Hra=9% of basic da= 5% of basic, allow=200, pf = 10% of basic

net salary = basic salary + hra +da +allow-pf. Print all details.
12. Write a program to accept marks of 5 subjects. Calculate total, percentage and acquired
division based on following criteria.

If perc>=60 division = first

If perc>=50 and less than 60 division = second

If perc>=40 and less than 50 division = third

If perc is less than 40 division= failed

If the student’s percentage is more than 80%, display “Eligible for scholar badge”
otherwise display “Not eligible “

13. Write a program to input three numbers and display the largest.
14. Write a program to accept 3 numbers from users. Display the numbers in descending order.

15. Write two print statements to print this.

print (“This” ,“is” ,“a“ , “bright” ,“sunny” ,“day”)

print (“This” , “is”, “a” , “fine”, “day”)

output :
This is a bright sunny day

This is a fine day

Append the above statements to print this:

a. This$is$a$bright$sunny$day
This…is…a…fine…day

b. This…is…a…bright…sunny…day$This…is…a…fine…day

16. Write a program to input number of seconds from the user and calculate the number of
hours, minutes and seconds.

Example - 1000 seconds = 0 hours 16 minutes and 40 seconds.

Hours – x second /3600. Min – hours/60 seconds - min/60


Hours = Seconds // 3600

Seconds = Seconds % 3600

Minutes = seconds //60

Seconds = Seconds % 60

Dry Run:

6000 – 1 hr and 40 mins.

7540 – 2 hr 5 min 40 sec - 7200 , 340 , 300 , 40

17. Input a number and produce n<n+1><n+2>

3 – 345 – 300 +40 +5

7 – 789 – 700 + 80 + 9

Formulae - number = (x * 100) + ((x+1) * 10) + (x + 2)

Don’t use this - print (x,x+1,x+2,sep=’’)

18. Program to swap three numbers - X, Y , Z as X=X+y and Y = Y+Z.

X, Y = X+Y , Y + Z

19. Program to input Name , Class and age of a student and print it.

Example : Shaurya , 11 , 15

Shaurya is in class 11 and has age 15

20. Program to convert Celsius to Fahrenheit using formulae

C * 9/5 +32 = F

21. Program to calculate BMI = Weight / Height * Height kg / m


22. Swap Three numbers 1-> 2, 2-> 3 and 3->1

You might also like