From c844467ee0c8785e64ad9c77154672915805e37d Mon Sep 17 00:00:00 2001 From: baphim <269010393+baphim@users.noreply.github.com> Date: Mon, 12 Oct 2026 10:50:19 -0400 Subject: [PATCH] feat: created initial files/comments. --- lab-05/exercise-14.py | 3 +++ lab-05/exercise-15.py | 4 ++++ lab-05/exercise-16.py | 4 ++++ lab-05/exercise-17.py | 4 ++++ lab-05/exercise-18.py | 5 +++++ lab-3_4/P-1.32.py | 20 +++++++++++++------- 6 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 lab-05/exercise-14.py create mode 100644 lab-05/exercise-15.py create mode 100644 lab-05/exercise-16.py create mode 100644 lab-05/exercise-17.py create mode 100644 lab-05/exercise-18.py diff --git a/lab-05/exercise-14.py b/lab-05/exercise-14.py new file mode 100644 index 0000000..655e45b --- /dev/null +++ b/lab-05/exercise-14.py @@ -0,0 +1,3 @@ +""" +Write a program to reverse a given integer number (e.g., 76542 should become 24567) +""" \ No newline at end of file diff --git a/lab-05/exercise-15.py b/lab-05/exercise-15.py new file mode 100644 index 0000000..8866a06 --- /dev/null +++ b/lab-05/exercise-15.py @@ -0,0 +1,4 @@ +""" +Write a program to find the largest and smallest digit within a given integer (e.g., in 75869, the largest is 9 and +the smallest is 5). +""" \ No newline at end of file diff --git a/lab-05/exercise-16.py b/lab-05/exercise-16.py new file mode 100644 index 0000000..7171c03 --- /dev/null +++ b/lab-05/exercise-16.py @@ -0,0 +1,4 @@ +""" +Write a program to check if a given number is a palindrome. A palindrome number is a number that remains the same +when its digits are reversed (e.g., 121, 343) +""" \ No newline at end of file diff --git a/lab-05/exercise-17.py b/lab-05/exercise-17.py new file mode 100644 index 0000000..4e73063 --- /dev/null +++ b/lab-05/exercise-17.py @@ -0,0 +1,4 @@ +""" +Write a program to use a loop to find the factorial of a given number (e.g., 5!). The factorial of N is the product +of all integers from 1 to N. +""" \ No newline at end of file diff --git a/lab-05/exercise-18.py b/lab-05/exercise-18.py new file mode 100644 index 0000000..328916d --- /dev/null +++ b/lab-05/exercise-18.py @@ -0,0 +1,5 @@ +""" +The Collatz conjecture states that if you start with any positive integer n, and if n is even, divide it by 2; if n is +odd, multiply it by 3 and add 1. Repeat the process. The sequence will always eventually reach 1. Write a program to +print this sequence for a given number. +""" \ No newline at end of file diff --git a/lab-3_4/P-1.32.py b/lab-3_4/P-1.32.py index 290a2a8..efe2772 100644 --- a/lab-3_4/P-1.32.py +++ b/lab-3_4/P-1.32.py @@ -4,6 +4,8 @@ device. That is, each input to the calculator, be it a number, like 12.34 or 103 done on a separate line. After each such input, you should output to the Python console what would be displayed on your calculator. """ + + # define a function that parses the operators tuple into actual operators and calculates result of the expression def calc(value1, operator, value2): if operator == "+": @@ -21,8 +23,11 @@ def calc(value1, operator, value2): # exits the function cleanly so result never holds None, preventing errors return None return result -# define global tuple of potential operators -operators = ("+", "-", "*", "/" ) + + +# define global tuple of potential operators +operators = ("+", "-", "*", "/") + def calculate(): value1 = None @@ -30,7 +35,9 @@ def calculate(): value2 = None # prompts for user input, exits program if 'q' is entered while True: - user_input = input("Enter a number, mathematic operator (+, -, *, /) or 'q' to quit: ") + user_input = input( + "Enter a number, mathematic operator (+, -, *, /) or 'q' to quit: " + ) if user_input == "q": break # if user inputs '=', prints message if nothing to calculate, prints 'value1' if stored @@ -80,18 +87,17 @@ def calculate(): # Stores input as 'value1' and prints it value1 = user_input print(value1) - # if operator is stored, tries input for valid float value + # if operator is stored, tries input for valid float value else: try: user_input = float(user_input) - # handle ValueError and print error message + # handle ValueError and print error message except ValueError: print("Please enter a valid number or operator") continue # stores input as 'value2' and prints current state of expression value2 = user_input print(value1, operator, value2) - -calculate() \ No newline at end of file +calculate()