0% found this document useful (0 votes)
12 views3 pages

Python Code

The document contains a series of Python programming examples demonstrating basic operations such as printing messages, arithmetic calculations, user input, and conditional statements. Each example includes the code and expected output, covering topics like addition, subtraction, data types, and simple interest calculations. It serves as a practical guide for beginners to learn fundamental programming concepts in Python.

Uploaded by

madhav563245
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)
12 views3 pages

Python Code

The document contains a series of Python programming examples demonstrating basic operations such as printing messages, arithmetic calculations, user input, and conditional statements. Each example includes the code and expected output, covering topics like addition, subtraction, data types, and simple interest calculations. It serves as a practical guide for beginners to learn fundamental programming concepts in Python.

Uploaded by

madhav563245
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.

Print a message
print("Hello World")
# Output: Hello World

# 2. Print name and class


print("Name: Madhav")
print("Class: 9")
# Output:
# Name: Madhav
# Class: 9

# 3. Add two numbers


a = 10
b = 20
print("Sum =", a + b)
# Output: Sum = 30

# 4. Subtract two numbers


a = 50
b = 30
print("Difference =", a - b)
# Output: Difference = 20

# 5. Multiply two numbers


x=5
y=6
print("Product =", x * y)
# Output: Product = 30

# 6. Divide two numbers


a = 20
b=4
print("Division =", a / b)
# Output: Division = 5.0

# 7. Find remainder
a = 17
b=5
print("Remainder =", a % b)
# Output: Remainder = 2

# 8. Check data type


x = 10
print(type(x))
# Output: <class 'int'>
# 9. Input and print name
name = input("Enter your name: ")
print("Hello", name)
# Output:
# Enter your name: Madhav
# Hello Madhav

# 10. Add two user input numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
# Output:
# Enter first number: 4
# Enter second number: 6
# Sum = 10

# 11. Square of a number


n = int(input("Enter a number: "))
print("Square =", n * n)
# Output:
# Enter a number: 5
# Square = 25

# 12. Cube of a number


n = int(input("Enter a number: "))
print("Cube =", n ** 3)
# Output:
# Enter a number: 3
# Cube = 27

# 13. Swap two numbers


a=5
b = 10
a, b = b, a
print("a =", a)
print("b =", b)
# Output:
# a = 10
#b=5

# 14. Average of three numbers


a = 10
b = 20
c = 30
avg = (a + b + c) / 3
print("Average =", avg)
# Output: Average = 20.0
# 15. Simple Interest
p = 1000
r=5
t=2
si = (p * r * t) / 100
print("Simple Interest =", si)
# Output: Simple Interest = 100.0

# 16. If statement (positive number)


num = int(input("Enter a number: "))
if num > 0:
print("Positive number")
# Output:
# Enter a number: 7
# Positive number

# 17. If-Else (even or odd)


num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
# Output:
# Enter a number: 9
# Odd number

# 18. If-Elif-Else (grade system)


marks = int(input("Enter marks: "))

if marks >= 90:


print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")
# Output:
# Enter marks: 82
# Grade B

You might also like