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

Combined Python Script

This document is a Python programming script that covers basic math operations, the use of the math module, and includes a leap year checker. It demonstrates loops (for and while), along with the use of functions to calculate the square and cube of a number. The script provides user prompts for input and outputs various mathematical results and loop iterations.

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)
15 views2 pages

Combined Python Script

This document is a Python programming script that covers basic math operations, the use of the math module, and includes a leap year checker. It demonstrates loops (for and while), along with the use of functions to calculate the square and cube of a number. The script provides user prompts for input and outputs various mathematical results and loop iterations.

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. Basic Math and Math Module Functions ---


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"\nSum = {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 # Added a small check since
log(0) throws an error

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. Leap Year Checker ---

print("\n--- Leap Year Checker ---")

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. Loops (For, While, Break, Continue) ---​
print("\n--- Loops and Iterations ---")​
fruits = ["apple", "grape", "orange"] ​

print("Iterating over a list:") ​
for fruit in fruits:​
print(fruit)​

print("\nLoop with break and continue:")​
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)​

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

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


# --- 5. Functions ---​
print("\n--- Functions ---")​
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