0% found this document useful (0 votes)
25 views4 pages

Basic Python Codes Grade X

The document provides 30 basic Python code examples suitable for Grade X students, covering fundamental programming concepts. Examples include printing messages, performing arithmetic operations, using loops, defining functions, and manipulating strings. Each code snippet is accompanied by a brief description of its purpose.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Basic Python Codes Grade X

The document provides 30 basic Python code examples suitable for Grade X students, covering fundamental programming concepts. Examples include printing messages, performing arithmetic operations, using loops, defining functions, and manipulating strings. Each code snippet is accompanied by a brief description of its purpose.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

30 Basic Python Codes for Grade X

Students
1. Print Hello World
print("Hello, World!")

2. Simple Addition
a = 5
b = 3
print("Sum:", a + b)

3. Simple Subtraction
a = 10
b = 4
print("Difference:", a - b)

4. Multiplication
a = 7
b = 6
print("Product:", a * b)

5. Division
a = 20
b = 5
print("Quotient:", a / b)

6. Modulus
a = 10
b = 3
print("Remainder:", a % b)

7. Power
a = 2
b = 3
print("Power:", a ** b)
8. Area of Circle
r = 5
area = 3.14 * r * r
print("Area:", area)

9. Swap Numbers
a, b = 5, 10
a, b = b, a
print("a =", a, "b =", b)

10. Check Even/Odd


num = 7
if num % 2 == 0:
print("Even")
else:
print("Odd")

11. Check Positive/Negative


num = -5
if num >= 0:
print("Positive")
else:
print("Negative")

12. Largest of Two Numbers


a, b = 10, 20
print("Largest:", a if a > b else b)

13. Largest of Three Numbers


a, b, c = 10, 25, 15
print("Largest:", max(a, b, c))

14. Simple For Loop


for i in range(5):
print(i)
15. While Loop Example
i = 1
while i <= 5:
print(i)
i += 1

16. Factorial of Number


n = 5
fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial:", fact)

17. Fibonacci Sequence


a, b = 0, 1
for i in range(5):
print(a)
a, b = b, a+b

18. Sum of Digits


num = 123
sum_digits = 0
for d in str(num):
sum_digits += int(d)
print("Sum:", sum_digits)

19. Reverse a String


s = "Python"
print(s[::-1])

20. Function Example


def greet(name):
print("Hello", name)
greet("Alice")
21. Square Function
def square(n):
return n*n
print(square(4))

22. Find Length of String


s = "Python"
print(len(s))

23. Count Vowels in String


s = "education"
vowels = "aeiou"
count = 0
for ch in s:
if ch in vowels:
count += 1
print("Vowels:", count)

You might also like