You are on page 1of 7

Page 113 (1&2)

def sum(a,b):
return a + b
num1= float(input("Enter the first number:"))
num2= float(input("Enter the second number:"))
print("the sum of", num1,"and",num2,"is:", sum(num1,num2))

def sum (a,b):


return a + b

def difference (a,b):


return a + b

def product (a,b):


return a + b

def quotient (a,b):


if b != 0:
return a/b
else:
return "Division by zero is not possible"

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


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

print("Choose the operation you want to perform:")


print("1-Add")
print("2-Subtract")
print("3-Multiply")
print("4-Divide")
choice = int(input("Enter your choice:"))

if choice ==1:
print("The sum of",num1, "and", num2, "is:", sum (num1,num2))
elif choice ==2:
print("The diffrence between",num1, "and", num2, "is:", difference (num1,num2))
elif choice ==3:
print("The product of",num1, "and", num2, "is:", product (num1,num2))
elif choice ==3:
print("The quotient of",num1, "and", num2, "is:", quotient (num1,num2))
else:
print("invalid choice")

Page 115 (1&2)


def get_full_name(first_name, last_name):
return last_name + "" + first_name

first_name = input("Enter your first name: ")


last_name = input("Enter your last name: ")

full_name = get_full_name(first_name, last_name)


print("Your full name is:", full_name)

num1 = int(input("Enter number 1: "))


num2 = int(input("Enter number 2: "))

if num1>num2:
print(num1,"is the largest.")
else:
print(num2,"is the largest.")
Page 118
import math
x = [3.12, 12.9, 5.37]
y = [6.61, 4.10, 98.48]

x_floor = [math.floor(i) for i in x]


x_ceiling = [math.ceil(i) for i in x]

y_floor = [math.floor(i) for i in y]


y_ceiling = [math.ceil(i) for i in y]

print("Floor values of x:", x_floor)


print("Ceiling values of x:", x_ceiling)
print("Floor values of x:", y_floor)
print("Ceiling values of x:", y_ceiling)
Page 119
import math
x = [3.12, 12.9, 5.37]
y = [6.61, 4.10, 98.48]

x_trunc = []
y_trunc = []
for i in range(len(x)):
x_trunc.append(math.trunc(x[i]))
y_trunc.append(math.trunc(y[i]))

print("Truncted list of x:", x_trunc)


print("Truncted list of y:", y_trunc)

Page 122
number = int(input("Enter a number:"))
result = number **3
print(f"{number} to the power of 3 is {result}")

Page 124
import math

numbers1 = [13,23,145]
gcd1 = math.gcd(*numbers1)
lcm1 = math.lcm(*numbers1)

print("number set 1:", numbers1)


print("GCD of set 1:", gcd1)
print("LCM of set 1:", lcm1)

numbers2 = [9,86,152,33,80]
gcd2 = math.gcd(*numbers2)
lcm2 = math.lcm(*numbers2)
print("number set 2:", numbers2)
print("GCD of set 2:", gcd2)
print("LCM of set 2:", lcm2)

Page 125

You might also like