0% found this document useful (0 votes)
2 views2 pages

Python Script

The document is a Python script that performs various mathematical operations, including basic arithmetic and functions from the math module. It also checks for leap years, iterates over lists, and demonstrates the use of loops and functions. Additionally, it includes a function to calculate the square and cube of a given number.

Uploaded by

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

Python Script

The document is a Python script that performs various mathematical operations, including basic arithmetic and functions from the math module. It also checks for leap years, iterates over lists, and demonstrates the use of loops and functions. Additionally, it includes a function to calculate the square and cube of a given number.

Uploaded by

pokewheel290
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import math​


# 1.​
print("Welcome to Python Programming")​

a = int(input("Enter an integer value for a: "))​
b = float(input("Enter a floating-point value for b: "))​

sum_val = a + b​
diff = a - b​
prod = a * b​
quotient = a / b​
floor_div = a // b​
remainder = a % b​
exp = a ** 2​

print(f"Sum = {sum_val}")​
print(f"Difference = {diff}")​
print(f"Product = {prod}")​
print(f"Division = {quotient}")​
print(f"Floor Division = {floor_div}")​
print(f"Modulus = {remainder}")​
print(f"Exponentiation (a ** 2) = {exp}")​

sqrt_val = [Link](a)​
power = [Link](a, b)​
sin_val = [Link]([Link](a))​
log_val = [Link](a) if a > 0 else 0 ​

print("\n--- Math Module Functions ---")​
print(f"Square root of a = {sqrt_val}")​
print(f"a raised to the power b = {power}")​
print(f"Sine of a degrees = {sin_val}")​
print(f"Natural logarithm of a = {log_val:.2f}")​

# 3.​
year = int(input("Enter a year: "))​

if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0): ​
print("Leap Year")​
else: ​
print("Not a Leap Year")​

# 4.​
fruits = ["apple", "grape", "orange"] ​
print("Iterating over a list:") ​
for i in fruits:​
print(i)​

for i in range(1, 10): ​
if i == 7: ​
print("Breaking the loop at", i)​
break​
if i % 2 == 0:​
continue​
print("Odd number:", i)​

for i in range(1, 3):​
for j in range(1, 3):​
print(f"i={i}, j={j}")​
else:​
print("For loop completed")​

n = 1​
while n <= 3:​
print(n)​
n += 1​
else:​
print("While loop completed")​

# 5.​
def calculate(number):​
square = number ** 2​
cube = number ** 3​
return square, cube​

num = int(input("Enter a number: "))​
sq, cb = calculate(num)​

print(f"Square of {num} is {sq}") ​
print(f"Cube of {num} is {cb}")​

You might also like