CHP 2 (Exercise)
CHP 2 (Exercise)
18#
Name: BILAL
Exercise 3.1
In [3]:
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is even")
else:
print(num, "is odd")
Enter a number: 47
47 is odd
Exercise 3.2
In [5]: year = int(input("Enter a year: "))
Exercise 3.3
In [6]: month = int(input("Enter the month number: "))
Exercise 3.4
In [7]: mass = 0.79 # given mass of potassium dichromate
molar_mass = 294 # molar mass of potassium dichromate
Exercise 3.9
In [8]: num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
1 of 4 25/03/2023, 2:24 am
Untitled12 - Jupyter Notebook http://localhost:8889/notebooks/Untitled12.ipynb?kernel_name=python3#Exercise-3.18#
Exercise 3.12
In [12]: x = float(input("Enter the x-coordinate of the point: "))
y = float(input("Enter the y-coordinate of the point: "))
if x == 0 and y == 0:
print("The point lies on the origin.")
elif x == 0:
print("The point lies on the y-axis.")
elif y == 0:
print("The point lies on the x-axis.")
elif x > 0 and y > 0:
print("The point lies in the first quadrant.")
elif x < 0 and y > 0:
print("The point lies in the second quadrant.")
elif x < 0 and y < 0:
print("The point lies in the third quadrant.")
else:
print("The point lies in the fourth quadrant.")
Exercise 3.13
In [15]: # function to determine if three points are collinear
def is_collinear(x1, y1, x2, y2, x3, y3):
# use the formula for the slope of a line
slope = (y2 - y1) * (x3 - x2) - (y3 - y2) * (x2 - x1)
return slope == 0
Exercise 3.14
In [16]: a = float(input("Enter the length of side a: "))
b = float(input("Enter the length of side b: "))
c = float(input("Enter the length of side c: "))
if a == b or b == c or c == a:
print("The triangle is an isosceles triangle")
else:
print("The triangle is not an isosceles triangle")
Exercise 3.15
2 of 4 25/03/2023, 2:24 am
Untitled12 - Jupyter Notebook http://localhost:8889/notebooks/Untitled12.ipynb?kernel_name=python3#Exercise-3.18#
Exercise 3.16
In [24]: a = int(input("Enter the first integer: "))
b = int(input("Enter the second integer: "))
c = int(input("Enter the third integer: "))
Exercise 3.17
In [20]: weight= int(input("Enter weight in kg :"))
if weight<=2:
print("The Shipping charges for weight",weight,"kg is Rs. 200")
elif weight<=6:
print("The Shipping charges for weight",weight,"kg is Rs. 400")
elif weight<=10:
print("The Shipping charges for weight",weight,"kg is Rs. 550")
else:
print("The Shipping charges for weight",weight,"kg is Rs. 700")
Exercise 3.18
In [22]: # Get the date from the user
date = input("Enter a date in mm/dd/yy format: ")
3 of 4 25/03/2023, 2:24 am
Untitled12 - Jupyter Notebook http://localhost:8889/notebooks/Untitled12.ipynb?kernel_name=python3#Exercise-3.18#
4 of 4 25/03/2023, 2:24 am