➔ Operators (Add)
Input:
a= int(input(“enter the first number:”))
b=int(input(“enter the second number:”))
c=a+b
print(c)
Output:
enter the first number:(Any number)
enter the second number:(Any number)
(Answer)
➔ Operators (Minus)
Input:
n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))
if n1 > n2:
diff = n1 - n2
else:
diff = n2 - n1
print("The difference is:",diff)
Output:
Enter first number: (Any number)
Enter second number: (Any number)
The difference is: (Answer)
➔ Even and Odd Numbers
Input:
x = int(input("Enter a number: "))
if (x% 2) == 0:
print(“It is an Even number")
else:
print(“It is an odd number")
Output:
Enter a number: (Any number)
It is an Odd / Even number
➔ Negative or positive number
Input:
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
Output:
Enter a number: (Any Number)
Positive / Negative number
➔ Name Loop
Input:
a=input("enter your name:")
x=0
while x<=10:
print(a)
x+=1
Output:
enter your name: (Your name)
(Your name) x 10
➔ Fibonaccci Series
Input:
a=0
b=1
for c in range(10):
d=a+b
print(d)
a=b
b=d
Output:
1
2
3
5
8
13
21
34
55
89
➔ Range for Even numbers
Input:
for a in range(2, 21, 2):
print(a)
Output:
2
4
6
8
10
12
14
16
18
20
➔ Range for Odd Numbers
Input:
for a in range(1,20, 2):
print(a)
Output:
1
3
5
7
9
11
13
15
17
19
➔ Even numbers
Input:
a=2
while a <= 20:
print(a)
a+=2
Output:
2
4
6
8
10
12
14
16
18
20
➔ Odd Numbers
Input:
a=1
while a <= 19:
print(a)
a+=2
Output:
1
3
5
7
9
11
13
15
17
19
➔ Prime number or not:
Input:
num = int(input("Enter a number: "))
# If number is greater than 1
if num > 1:
# Check if factor exist
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number")
# Else if the input number is less than or equal to 1
else:
print(num,"is not a prime number")
Output:
Enter a number: (Any number)
Number is (Prime or not)
➔ Multi table
Input:
number = int(input ("Enter the number of which the user wants to print the multiplication
table: "))
print ("The Multiplication Table of: ", number)
for count in range(1, 11):
print (number, 'x', count, '=', number * count)
Output:
Enter the number of which the user wants to print the multiplication table: N
The Multiplication Table of: 10
Nx1=n
Nx2=n
Nx3=n
Nx4=n
Nx5=n
Nx6=n
N x7=n
N x8=n
N x9=n
N x 10 = n