1. Hello World Program
Explanation:
-
print() is used to display output.
-
"Hello, World!" is a string (text inside quotes).
-
This is the first program to check if Python is working.
2. Add Two Numbers
Explanation:
-
input() takes user input (as string).
-
int() converts input into integer.
-
a + b adds both numbers.
-
print() displays the result.
3. Check Even or Odd
Explanation:
-
% is modulus (remainder operator).
-
If a number divided by 2 gives remainder
0, it's even.
-
if-else is used for decision making.
4. Largest of Three Numbers
Explanation:
-
and checks multiple conditions.
-
First condition checks if
a is largest.
-
elif checks second condition.
-
else handles the remaining case.
5. Simple Calculator
Explanation:
-
float() allows decimal numbers.
-
op stores the operation symbol.
-
Based on the symbol, different operations are performed.
6. Factorial of a Number
Explanation:
-
Factorial =
1 × 2 × 3 × ... × n
-
range(1, num+1) loops from 1 to num.
-
fact *= i means fact = fact * i.
7. Multiplication Table
Explanation:
-
Loop runs from 1 to 10.
-
Each time it multiplies
num * i.
8. Reverse a String
Explanation:
-
[::-1] is slicing.
-
It reverses the string.
-
Very powerful Python shortcut.
9. Count Vowels
Explanation:
-
Loop checks each character.
-
if char in vowels checks if it is a vowel.
-
count += 1 increases counter.
10. Check Prime Number
Explanation:
-
Prime numbers are divisible only by 1 and itself.
-
Loop checks divisibility from 2 to num-1.
-
break stops loop if divisor found.
-
else runs only if loop completes fully.
0 Comments