Title: Mathematics Practical
Assignment 1: Introduction to Python
Installation of Python
● Values and Types :int ,float,str,etc
● Variables: assignment statements ,printing variable values, types of variables
● Boolean operators, Logical operators
● Mathematical functions from math, cmath, modules.
-
Q1) Write a python Program for Value And Types Python Program Int, Float, String.
ans :
age = 25
height = 5.9
name = “Alice”
print(“Age:”, age)
print(“Type of age:”, type(age))
print(“Height:”, height)
print(“Type of height:”, type(height))
print(“Name:”, name)
print(“Type of name:”, type(name))
-
Q2) Write a python Program for variable assignment statement
Ans:-
-
age = 25
print(“The age is:”, age)
height = 5.9
print(“The height is:”, height)
name = “Alice”
print(“The name is:”, name)
# Assigning a boolean value to a variable
is_student = True
print(“Is the person a student?”, is_student)
# Assigning multiple variables at once
x, y, z = 10, 20, 30
print(“Values of x, y, and z are:”, x, y, z)
# Swapping values between variables
a, b = 5, 10
print(“Before swapping: a =”, a, “, b =”, b)
a, b = b, a
print(“After swapping: a =”, a, “, b =”, b)
# Assigning a value to multiple variables
m = n = o = 50
print(“Values of m, n, and o are:”, m, n, o)
-
Q3) Write a python Program for variable printing variable value and types of variable.
Ans:-
-
# Define variables of different types
integer_var = 42
float_var = 3.14
string_var = “Hello, World!”
boolean_var = True
list_var = [1, 2, 3, 4, 5]
# Print the value and type of each variable
print(“Value:”, integer_var, “Type:”, type(integer_var))
print(“Value:”, float_var, “Type:”, type(float_var))
print(“Value:”, string_var, “Type:”, type(string_var))
print(“Value:”, boolean_var, “Type:”, type(boolean_var))
print(“Value:”, list_var, “Type:”, type(list_var))
-
Q4) Write a python Program for Boolean operator And Logical Operator.
Ans:-
a = True
b = False
# Logical Operators
print(“a and b:”, a and b) # Logical AND
print(“a or b:”, a or b) # Logical OR
print(“not a:”, not a) # Logical NOT
# Combining Boolean and Logical Operators
x = 10
y = 20
# Example 1: Logical AND
result1 = (x > 5) and (y < 25)
print(“Result of (x > 5) and (y < 25):”, result1)
# Example 2: Logical OR
result2 = (x < 5) or (y < 25)
print(“Result of (x < 5) or (y < 25):”, result2)
# Example 3: Logical NOT
result3 = not (x > 5)
print(“Result of not (x > 5):”, result3)
-
Q5) Write a python Program for mathematical function from math, cmath, modules
Ans:-
-
import math
import cmath
# Example values
number = 16
complex_number = 1 + 2j
# Using math module
print(“Using math module:”)
print(f”Square root of {number}: {math.sqrt(number)}”)
print(f”Factorial of 5: {math.factorial(5)}”)
print(f”Cosine of 45 degrees: {math.cos(math.radians(45))}”)
print(f”Logarithm (base 10) of 100: {math.log10(100)}”)
# Using cmath module
print(“\nUsing cmath module:”)
print(f”Square root of {complex_number}: {cmath.sqrt(complex_number)}”)
print(f”Exponent of {complex_number}: {cmath.exp(complex_number)}”)
print(f”Logarithm of {complex_number}: {cmath.log(complex_number)}”)
print(f”Polar coordinates of {complex_number}: {cmath.polar(complex_number)}”)
# For completeness, let’s use some trigonometric functions from math
angle_degrees = 30
angle_radians = math.radians(angle_degrees)
print(f”\nTrigonometric functions for angle {angle_degrees} degrees:”)
print(f”Sine of {angle_degrees} degrees: {math.sin(angle_radians)}”)
print(f”Tangent of {angle_degrees} degrees: {math.tan(angle_radians)}”)