Update Lesson 3 Task 1 to call the numbers correctly

This commit is contained in:
Stanislav Mykhailenko 2023-01-04 01:09:19 +02:00
parent 6c4c9ac3c0
commit 985e45eb08
GPG key ID: 1E95E66A9C9D6A36

View file

@ -12,15 +12,15 @@
import sys import sys
def add (a, b): return a + b def add (firstNumber, secondNumber): return firstNumber + secondNumber
def substract(a, b): return a - b def substract(firstNumber, secondNumber): return firstNumber - secondNumber
def multiply(a, b): return a * b def multiply(firstNumber, secondNumber): return firstNumber * secondNumber
def divide(a, b): def divide(firstNumber, secondNumber):
if b == 0: if secondNumber == 0:
print("Division by zero.") print("Division by zero.")
sys.exit(2) sys.exit(2)
else: else:
return a / b return firstNumber / secondNumber
def square(number): return number**2 def square(number): return number**2
def isNatural(number): return False if number < 1 or not number.is_integer() else True def isNatural(number): return False if number < 1 or not number.is_integer() else True
@ -41,8 +41,8 @@ def root(number, degree):
return number ** (1 / degree) return number ** (1 / degree)
try: try:
numberA = float(input("Enter number A: ")) firstNumber = float(input("Enter the first number: "))
numberB = float(input("Enter number B: ")) secondNumber = float(input("Enter the second number: "))
except ValueError: except ValueError:
print("Invalid numbers entered.") print("Invalid numbers entered.")
sys.exit(1) sys.exit(1)
@ -61,17 +61,17 @@ Square: square or ² (of both numbers)''', end="\n\n"
operation = input("Enter operation: ") operation = input("Enter operation: ")
if operation == "+": if operation == "+":
print(add(numberA, numberB)) print(add(firstNumber, secondNumber))
elif operation == "-" or operation == "": # ASCII hyphen-minus or Unicode minus elif operation == "-" or operation == "": # ASCII hyphen-minus or Unicode minus
print(substract(numberA, numberB)) print(substract(firstNumber, secondNumber))
elif operation == "*" or operation == "×": # ASCII asterisk or Unicode multiplication sign elif operation == "*" or operation == "×": # ASCII asterisk or Unicode multiplication sign
print(multiply(numberA, numberB)) print(multiply(firstNumber, secondNumber))
elif operation == "/" or operation == "÷": # ASCII slash or Unicode division sign elif operation == "/" or operation == "÷": # ASCII slash or Unicode division sign
print(divide(numberA, numberB)) print(divide(firstNumber, secondNumber))
elif operation == "root" or operation == "": # Unicode radical symbol elif operation == "root" or operation == "": # Unicode radical symbol
print(root(numberA, numberB)) print(root(firstNumber, secondNumber))
elif operation == "square" or operation == "²": # Unicode superscript 2 elif operation == "square" or operation == "²": # Unicode superscript 2
print("Number A square: " + str(square(numberA)) + "\nNumber B square: " + str(square(numberB))) print("Number A square: " + str(square(firstNumber)) + "\nNumber B square: " + str(square(secondNumber)))
else: else:
print("Invalid operation.") print("Invalid operation.")
sys.exit(5) sys.exit(5)