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

Python Basics: 30 Essential Scripts

The document contains a series of Python code snippets demonstrating basic programming operations such as printing messages, arithmetic calculations, area and perimeter calculations, conversions between units, and simple data manipulations. Each snippet is labeled with a brief description of its function, making it a useful reference for beginners learning Python. The examples cover a wide range of topics, including interest calculations, number properties, and basic input/output.

Uploaded by

vamsiskn
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)
4 views3 pages

Python Basics: 30 Essential Scripts

The document contains a series of Python code snippets demonstrating basic programming operations such as printing messages, arithmetic calculations, area and perimeter calculations, conversions between units, and simple data manipulations. Each snippet is labeled with a brief description of its function, making it a useful reference for beginners learning Python. The examples cover a wide range of topics, including interest calculations, number properties, and basic input/output.

Uploaded by

vamsiskn
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 'Hello, World!

'
print('Hello, World!')

2. Add two numbers


a = 5 b = 3 print('Sum =', a + b)

3. Subtract two numbers


a = 10 b = 4 print('Difference =', a - b)

4. Multiply two numbers


a = 6 b = 7 print('Product =', a * b)

5. Divide two numbers


a = 20 b = 5 print('Quotient =', a / b)

6. Find remainder (modulus)


a = 22 b = 5 print('Remainder =', a % b)

7. Swap two numbers


a, b = 10, 20 a, b = b, a print('a =', a, 'b =', b)

8. Square of a number
num = 4 print('Square =', num ** 2)

9. Cube of a number
num = 3 print('Cube =', num ** 3)

10. Area of a rectangle


length = 5 breadth = 3 print('Area =', length * breadth)

11. Area of a circle


r = 7 print('Area =', 3.14 * r * r)

12. Perimeter of a rectangle


length = 5 breadth = 3 print('Perimeter =', 2 * (length + breadth))

13. Circumference of a circle


r = 7 print('Circumference =', 2 * 3.14 * r)

14. Convert Celsius to Fahrenheit


c = 25 f = (c * 9/5) + 32 print('Fahrenheit =', f)

15. Convert Fahrenheit to Celsius


f = 77 c = (f - 32) * 5/9 print('Celsius =', c)
16. Simple Interest calculator
p, r, t = 1000, 5, 2 si = (p * r * t) / 100 print('Simple Interest =', si)

17. Compound Interest calculator


p, r, t = 1000, 5, 2 ci = p * (1 + r/100)**t - p print('Compound Interest =', ci)

18. Check even or odd number


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

19. Find largest of two numbers


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

20. Find largest of three numbers


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

21. Calculate BMI


h = 1.75 w = 70 bmi = w / (h ** 2) print('BMI =', bmi)

22. Find square root of a number


import math num = 16 print('Square Root =', [Link](num))

23. Convert kilometers to miles


km = 5 miles = km * 0.621371 print('Miles =', miles)

24. Convert inches to centimeters


inch = 10 cm = inch * 2.54 print('Centimeters =', cm)

25. Convert hours to minutes and seconds


hours = 2 minutes = hours * 60 seconds = hours * 3600 print(minutes, 'minutes',
seconds, 'seconds')

26. Reverse a number


num = 123 rev = int(str(num)[::-1]) print('Reversed =', rev)

27. Sum of digits of a number


num = 123 s = sum(int(d) for d in str(num)) print('Sum of digits =', s)

28. Print multiplication table of a number


num = 5 for i in range(1, 11): print(num, 'x', i, '=', num*i)

29. Find the average of three numbers


a, b, c = 10, 20, 30 print('Average =', (a + b + c)/3)
30. Simple Calculator
a, b = 10, 5 print('Add =', a+b) print('Sub =', a-b) print('Mul =', a*b) print('Div
=', a/b)

You might also like