You are on page 1of 6

PROGRAM 1 Working with numbers

import random

import math

u = int(input("Enter first number :"))

v = int(input("Enter second number :"))

sum1 = u + v

print("Addition of two numbers =",sum1)

var_int = 123

var_flo = 1.23

var_new = var_int + var_flo

print("datatype of num_int:",type(var_int))

print("datatype of num_flo:",type(var_flo))

print("Value of num_new:",var_new)

print("datatype of num_new:",type(var_new))

var3 = "Hello"

print("datatype of Hello :",type(var3))

var4 = 10

var5 = 2
1
addt = var4 + var5

sub = var4 - var5

mul = var4 * var5

div = var4 / var5

print("Sum of two numbers =", addt)

print("Subtraction of two numbers =", sub)

print("Division of two numbers =",div)

print("Multiplication of two numbers =", mul)

var6 = 3

mod1 = var4 % var6

print(var4, "Mod of", var6, "=",mod1)

var7 = 2+2j

var8 = 3+4j

addc = var7 + var8

print("Complex Number1 is", var7)

print("Complex Number1 is", var8)

print("sum of complex numbers is :", addc)

x =1

y = 2.0

z = 2+3j
2
a=float(x)

b=int(x)

c=complex(x)

d=complex(y)

print(a,type(a))

print(b,type(b))

print(c,type(c))

print(d,type(d))

print("Random numbers",random.randrange(1,15))

f=1.01

g=4.45

print(" Rounded value of",f,"is",round(f))

print(" Rounded value of",g,"is",round(g))

a1=-1.5

b1=2.3

c1=0

d1=2

print("The absolute Value of",a1,"is",abs(a1))

print("The absolute Value of",b1,"is",abs(b1))

print("The absolute Value of",c1,"is",abs(c1))

print("The absolute Value of",d1,"is",abs(d1))


3
base =8

power=2

print("Raise the power of base 8 to 2", pow(base,power))

a2=2.3

print("the ceil of 2.3 is ", math.ceil(a2))

print("the floor of 2.3 is ", math.floor(a2))

a3=-10

b3=5

c3=15

print("the absolute value of -10 is", math.fabs(a3))

print("the factorial of 5 is", math.factorial(b3))

print("the GCD of 5 & 15 is", math.gcd(b3,c3))

Output

>>>

= RESTART:
C:/Users/UMASIKAMANI/AppData/Local/Programs/Python/Python39/lab
prg/labprg1.py

Enter first number :100

4
Enter second number :200

Addition of two numbers = 300

datatype of num_int: <class 'int'>

datatype of num_flo: <class 'float'>

Value of num_new: 124.23

datatype of num_new: <class 'float'>

datatype of Hello : <class 'str'>

Sum of two numbers = 12

Subtraction of two numbers = 8

Division of two numbers = 5.0

Multiplication of two numbers = 20

10 Mod of 3 = 1

Complex Number1 is (2+2j)

Complex Number1 is (3+4j)

sum of complex numbers is : (5+6j)

1.0 <class 'float'>

1 <class 'int'>

(1+0j) <class 'complex'>

(2+0j) <class 'complex'>

Random numbers 12

Rounded value of 1.01 is 1

Rounded value of 4.45 is 4

The absolute Value of -1.5 is 1.5


5
The absolute Value of 2.3 is 2.3

The absolute Value of 0 is 0

The absolute Value of 2 is 2

Raise the power of base 8 to 2 64

the ceil of 2.3 is 3

the floor of 2.3 is 2

the absolute value of -10 is 10.0

the factorial of 5 is 120

the GCD of 5 & 15 is 5

>>>

You might also like