[Go to site: main page, start]

0% found this document useful (0 votes)
5 views7 pages

Python Program

The document provides a comprehensive guide to basic Python programming concepts, including printing outputs, using variables, taking user input, and performing arithmetic operations. It covers various examples such as printing text, using escape characters, and creating a simple calculator. Each section includes theory, program code, and sample outputs for clarity.

Uploaded by

mahirpatel9099
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 views7 pages

Python Program

The document provides a comprehensive guide to basic Python programming concepts, including printing outputs, using variables, taking user input, and performing arithmetic operations. It covers various examples such as printing text, using escape characters, and creating a simple calculator. Each section includes theory, program code, and sample outputs for clarity.

Uploaded by

mahirpatel9099
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

1.

Hello World Program

Theory

The print() function is used to display output on the screen.

Program

print("Hello World")

Output

Hello World

2. Print Multiple Lines

Theory

You can use multiple print() statements to display multiple lines.

Program

print("Welcome to Python")
print("This is my first program")
print("Python is easy to learn")

Output

Welcome to Python
This is my first program
Python is easy to learn

3. Print Using Escape Characters

Theory

Escape characters allow special formatting.

• \n → New Line

• \t → Tab Space

Program

print("Name:\tTushar")
print("Department:\tComputer")
print("Python\nProgramming")

Output

Name: Tushar
Department: Computer
Python
Programming
4. Print Different Data Types

Theory

Python supports different data types.

Program

print(25)
print(12.5)
print(True)
print("Python")

Output

25
12.5
True
Python

5. Variables

Theory

Variables store values.

Program

name = "Rahul"
age = 20
marks = 85.5

print(name)
print(age)
print(marks)

Output

Rahul
20
85.5

6. Printing Variables with Text

Program

name = "Rahul"
age = 20
print("Name =", name)
print("Age =", age)

Output

Name = Rahul
Age = 20

7. Taking Input from User

Theory

The input() function accepts user input.

Program

name = input("Enter your name: ")

print("Welcome", name)

Sample Output

Enter your name: Rahul


Welcome Rahul

8. Input Integer

Program

age = int(input("Enter your age: "))

print("Your age is", age)

Sample Output

Enter your age: 20


Your age is 20

9. Add Two Numbers

Program

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

sum = a + b

print("Sum =", sum)

Sample Output
Enter first number: 15
Enter second number: 20
Sum = 35

10. Subtract Two Numbers

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

print("Difference =", a - b)

Output

Enter first number: 20


Enter second number: 10
Difference = 10

11. Multiply Two Numbers

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

print("Multiplication =", a * b)

Output

Enter first number: 5


Enter second number: 8
Multiplication = 40

12. Divide Two Numbers

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

print("Division =", a / b)

Output

Enter first number: 20


Enter second number: 5
Division = 4.0

13. Calculate Square

num = int(input("Enter a number: "))

square = num ** 2
print("Square =", square)

Output

Enter a number: 6
Square = 36

14. Calculate Cube

num = int(input("Enter a number: "))

cube = num ** 3

print("Cube =", cube)

Output

Enter a number: 4
Cube = 64

15. Swap Two Numbers (Using Third Variable)

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

temp = a
a=b
b = temp

print("After Swapping")
print("a =", a)
print("b =", b)

Output

Enter first number: 10


Enter second number: 20

After Swapping
a = 20
b = 10

16. Swap Without Third Variable

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))
a, b = b, a

print("a =", a)
print("b =", b)

Output

Enter first number: 5


Enter second number: 8
a=8
b=5

17. Area of Rectangle

length = float(input("Enter Length: "))


width = float(input("Enter Width: "))

area = length * width

print("Area =", area)

Output

Enter Length: 10
Enter Width: 5
Area = 50.0

18. Area of Circle

radius = float(input("Enter Radius: "))

area = 3.14 * radius * radius

print("Area =", area)

Output

Enter Radius: 7
Area = 153.86

19. Average of Three Numbers

a = int(input("Enter First Number: "))


b = int(input("Enter Second Number: "))
c = int(input("Enter Third Number: "))

average = (a + b + c) / 3
print("Average =", average)

Output

Enter First Number: 10


Enter Second Number: 20
Enter Third Number: 30
Average = 20.0

20. Simple Calculator

a = float(input("Enter First Number: "))


b = float(input("Enter Second Number: "))

print("Addition =", a + b)
print("Subtraction =", a - b)
print("Multiplication =", a * b)
print("Division =", a / b)

Output

Enter First Number: 20


Enter Second Number: 5

Addition = 25.0
Subtraction = 15.0
Multiplication = 100.0
Division = 4.0

You might also like