0% found this document useful (0 votes)
7 views11 pages

CODES

The document contains multiple code snippets demonstrating basic mathematical operations in Python, including summing two numbers, calculating square roots, finding areas, and identifying the largest number among three. Each code snippet is followed by an example output illustrating the result of the operation. Additionally, it includes user input examples for dynamic calculations.

Uploaded by

prishakawrani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

CODES

The document contains multiple code snippets demonstrating basic mathematical operations in Python, including summing two numbers, calculating square roots, finding areas, and identifying the largest number among three. Each code snippet is followed by an example output illustrating the result of the operation. Additionally, it includes user input examples for dynamic calculations.

Uploaded by

prishakawrani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CODE 1

# sum of any two number with pre-defined variables


num1 = 30
num2 = 40
print ("the sum of given two number is", num1+num2)

OUTPUT
The sum of given two number is 70
CODE 2
# sum of any two number with user-inputs

num1 = float(input"enter a number here: "))


num2 = float(input("enter another number here: "))

sum= num1 + num2

print ("the sum of the provided two numbers is", sum)

OUTPUT

enter a number here: 20


enter another number here: 15
the sum of the provided two numbers is 35.0
CODE 3
# to find the square root of a number

num = 64
sr = num**(1/2)
print ("the square root of the given number is",sr)

OUTPUT

the square root of the given number is 8.0


CODE 4
# to find the area of a rectangle

breadth = float(input("enter the breadth of the rectangle: "))


length = float (input("enter the length of the rectangle: "))

area = l*b

print('the area of the rectangle is',area)

OUTPUT

enter the breadth of the rectangle: 8


enter the length of the rectangle: 12
the area of the rectangle is 96.0
CODE 5
# to find the largest among three numbers

num1 = 12
num2 = 56
num3 = 34

if (num1 > num2) and (num1 > num3):


print (num1, "is the largest number")
elif (num2 > num1) and (num2 > num3):
print (num2, "is the largest number")
else:
print (num3,"is the largest number")

OUTPUT

56 is the largest number


CODE 6
# to subtract num1 from num2

num1= 20
num2 = 48
result = num2 – num1
print (result)

OUTPUT

result is 28
CODE 7
# to find square of number 9

n=9
print("square of n is:",n**2)

OUTPUT

Square of 9 is: 81
CODE 8
# to input a number and display whether it is even or odd

num=int (input("enter a number: "))


if num%2==0:
print (num,"is EVEN")
else:
print (num,"is ODD")

OUTPUT

enter a number: 31
31 is ODD
CODE 9
# to find the average of two numbers

num1 = float(input("enter the first number: "))


num2 = float(input(" enter the second number: "))

average = (num1 + num2) / 2

print(f" the average of num1 and num2 is:{average}")

OUTPUT

enter the first number: 14


enter the second number: 18
the average of num1 and num2 is:16.0
CODE 10
# to find the base raised to power of exponent

base = float(input("enter the base number: "))


exponent = float(input("enter the exponent: "))
result = base**exponent
print(f" base raised to the power of the exponent is: {result}")

OUTPUT

enter the base number: 3


enter the exponent: 5
base raised to the power of the exponent is: 243.0

You might also like