Code:
print("Hello World")
Explanation:
print("Hello World") -> prints text to console
Addition of Two Numbers
Code:
a=5
b = 10
print(a + b)
Explanation:
a = 5 -> assign value 5
b = 10 -> assign value 10
print(a + b) -> prints sum
Even or Odd
Code:
num = 4
if num % 2 == 0:
print("Even")
else:
print("Odd")
Explanation:
num % 2 -> remainder
== 0 -> check even
if/else -> decision making
Factorial
Code:
n=5
fact = 1
for i in range(1, n+1):
fact *= i
print(fact)
Explanation:
loop from 1 to n
fact *= i -> multiply
print result
Reverse String
Code:
s = "hello"
print(s[::-1])
Explanation:
[::-1] -> reverse string