Python Arithmetic operator examples 1

Example:4

a=10**2 
print(a) 
a=5**2
print(a)
print(10**3) 
print(5**3)

Output:

100
25
1000
125
>>>

Example:5
Write a python script to take input for two numbers calculate and print their sum, product and difference?
Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
s=a+b
p=a*b
d=a-b
print("Sum = ",s)
print("Prod = ",p)
print("Diff = ",d)

Output:

Enter 1st no 10
Enter 2nd no 20
Sum = 30
Prod = 200
Diff = -10
>>>

Example:6
Write a python script to take input for three numbers calculate and print their average?
Sol:

a=float(input("Enter 1st no "))
b=float(input("Enter 2nd no "))
c=float(input("Enter 3rd no "))
d=(a+b+c)/3
print("Average = ",d)

Output:

Enter 1st no 25.36
Enter 2nd no 653.2
Enter 3rd no 45.23
Average = 241.26333333333335
>>>

Example:7
Write a python script to take input for total number of days and convert them into week and days? [ 1 week = 7 days]
Sol:

d=int(input("Enter total days "))
w=d//7
d=d%7
print(w," week ",d," days")

Output:

Enter total days 10
1 week 3 days
>>>
Enter total days 25
3 week 4 days
>>>