feat: created initial files/comments.
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
"""
|
||||||
|
Write a program to reverse a given integer number (e.g., 76542 should become 24567)
|
||||||
|
"""
|
||||||
@@ -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).
|
||||||
|
"""
|
||||||
@@ -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)
|
||||||
|
"""
|
||||||
@@ -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.
|
||||||
|
"""
|
||||||
@@ -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.
|
||||||
|
"""
|
||||||
+9
-3
@@ -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
|
done on a separate line. After each such input, you should output to the Python console what would be displayed on your
|
||||||
calculator.
|
calculator.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# define a function that parses the operators tuple into actual operators and calculates result of the expression
|
# define a function that parses the operators tuple into actual operators and calculates result of the expression
|
||||||
def calc(value1, operator, value2):
|
def calc(value1, operator, value2):
|
||||||
if operator == "+":
|
if operator == "+":
|
||||||
@@ -21,8 +23,11 @@ def calc(value1, operator, value2):
|
|||||||
# exits the function cleanly so result never holds None, preventing errors
|
# exits the function cleanly so result never holds None, preventing errors
|
||||||
return None
|
return None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# define global tuple of potential operators
|
# define global tuple of potential operators
|
||||||
operators = ("+", "-", "*", "/" )
|
operators = ("+", "-", "*", "/")
|
||||||
|
|
||||||
|
|
||||||
def calculate():
|
def calculate():
|
||||||
value1 = None
|
value1 = None
|
||||||
@@ -30,7 +35,9 @@ def calculate():
|
|||||||
value2 = None
|
value2 = None
|
||||||
# prompts for user input, exits program if 'q' is entered
|
# prompts for user input, exits program if 'q' is entered
|
||||||
while True:
|
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":
|
if user_input == "q":
|
||||||
break
|
break
|
||||||
# if user inputs '=', prints message if nothing to calculate, prints 'value1' if stored
|
# if user inputs '=', prints message if nothing to calculate, prints 'value1' if stored
|
||||||
@@ -93,5 +100,4 @@ def calculate():
|
|||||||
print(value1, operator, value2)
|
print(value1, operator, value2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
calculate()
|
calculate()
|
||||||
Reference in New Issue
Block a user