From 5c02a451a8daca2ebf72b45c257d8895b597ec9c Mon Sep 17 00:00:00 2001 From: Donaldodan <95238102+Donaldodan@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:50:08 +0200 Subject: [PATCH 1/2] Update Basic calculator --- Basic calculator | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Basic calculator b/Basic calculator index 30b6619..181a179 100644 --- a/Basic calculator +++ b/Basic calculator @@ -1,4 +1,3 @@ -#Donald's Basic calculator #this function adds two numbers def add(x,y): return x + y @@ -19,6 +18,10 @@ def divide(x,y): def modulus(x,y): return x % y +#this function gives the exponent of two numbers +def exponent(x, y): + return x ** y + print('''Welcome! Simple calculator @@ -28,13 +31,14 @@ print('2.subtract') print('3.multiply') print('4.divide') print('5.modulus') +print('6.exponent') while True: #take input from the user - choice = input('Enter choice(1/2/3/4/5):') + choice = input('Enter choice(1/2/3/4/5/6):') #check if the choice is one of the five options - if choice in ('1','2','3','4','5'): + if choice in ('1','2','3','4','5','6'): try: num1 = float(input('Enter first number:')) num2 = float(input('Enter second number')) @@ -57,6 +61,9 @@ while True: elif choice == '5': print (num1, '+', num2, '=', modulus(num1, num2)) + elif choice == '6': + print (num1, '+', num2, '=', exponent(num1, num2)) + #check if user wants another calculation # break the while loop if the answer is no From 4131aa36dc375b3df61bab61edb623206e1729c3 Mon Sep 17 00:00:00 2001 From: Donaldodan <95238102+Donaldodan@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:56:02 +0200 Subject: [PATCH 2/2] Update Basic calculator --- Basic calculator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Basic calculator b/Basic calculator index 181a179..a9ace0b 100644 --- a/Basic calculator +++ b/Basic calculator @@ -37,7 +37,7 @@ while True: #take input from the user choice = input('Enter choice(1/2/3/4/5/6):') - #check if the choice is one of the five options + #check if the choice is one of the six options if choice in ('1','2','3','4','5','6'): try: num1 = float(input('Enter first number:'))