5 Basic program of python
This 5 basic program you must know
1. Hello world
input :- print("Hello, World!")
2. Arithmetic operations
input :-
a = 10
b = 5
print("Sum of a and b:", a+b)
print("Difference of a and b:", a-b)
print("Product of a and b:", a*b)
print("Quotient of a and b:", a/b)
3. Check if a number is even of odd
input :-
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is even")
else:
print(num, "is odd")
4. Check if a number is positive, negative or zero
input :-
num = int(input("Enter a number: "))
if num > 0:
print(num, "is positive")
elif num < 0:
print(num, "is negative")
else:
print(num, "is zero")
5. Find the factorial of a number
input :-
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num+1):
factorial *= i
print("Factorial of", num, "is", factorial)
0 Comments