# data[].attributes.body
def add(x, y):

return x + y

def subtract(x, y):

return x - y

def multiply(x, y):

return x * y

def divide(x, y):

return x / y

cont="yes"

running=True

while running:

try:

num1 = int(input("Enter first number: "))

except ValueError:

print("Invalid input. Please enter a number.")

continue

try:

num2 = int(input("Enter second number: "))

except ValueError:

print("Invalid input. Please enter a number.")

continue

op = input("Enter operator: +, -, / or *: ")

if op == "+":

ans = add(num1, num2)

elif op == "-":

ans = subtract(num1, num2)

elif op == "*":

ans = multiply(num1, num2)

elif op == "/":

ans=divide(num1, num2)

if num2 == 0:

print("Zero division error")

ans = divide(num1, num2)

else:

print("Invalid operator")

print("Answer:", ans)

cont = input("Do you want to continue? (yes or no)")

if cont == "no":

running = False

# data[].attributes.body
def add(a, b):

return a+b

def subtract(a, b):

return a-b

def multiply(a, b):

return a*b

def divide(a, b):

return a/b

def main():

running= True

while True:

a=int(input("enter number 1: "))

b=int(input("enter number 2: "))

op=input("please enter the operation you would like to perform, +, -, *, /: ")

if op=="+":

ans=add(a,b)

print("the answer is = ", ans)

elif op=="-":

ans=subtract(a,b)

print("the answer is = ", ans)

elif op=="*":

ans=multiply(a,b)

print("the answer is = ", ans)

elif op=="/" and b==0:

print("Zero error: Cannot divide by zero")

elif op=="/":

if b==0:

print("zero error: cannot divide by zero")

else:

ans=divide(a,b)

print("the answer is = ", ans)

else:

print("invalid operator, pick +, -, * or /")

cont=input("do you want to continue? y/n: ")

if cont=='n':

running=False

main()

# data[].attributes.body
def add(x,y):
  return x + y
def sub(x,y):
  return x-y
def mul(x,y):
  return x*y
def div(x,y):
  return x/y
#our main function
def main():
  running = True

  while running:
    num1=int(input("Enter number 1: "))
    num2=int(input("Enter number 2: "))

    op=input("Enter operation (+ - * /): ")

    if op=="+":
      ans=add(num1,num2)
      print("Answer: ",ans)
    elif op=="-":
      ans=sub(num1,num2)
      print("Answer: ",ans)
    elif op=="*":
      ans=mul(num1,num2)
      print("Answer: ",ans)
    elif op=="/":
      if num2 !=0:
        ans=div(num1,num2)
        print("Answer: ",ans)
      else :
        print("Cannot divide by zero")
    else:
     will_continue = input("Type 'yes' to continue and 'no' to exit: ")
     if will_continue =='no':
      running = False





main()

# data[].attributes.body
def add(a, b):

return a + b

def sub(a, b):

return a - b

def mul(a, b):

return a * b

def div(a, b):

return a / b

def main():

running=True

while running:

num1 = int(input("Enter number 1: "))

num2 = int(input("Enter number 2: "))

op = input("Enter operation (+ - * /): " )

if op == "+":

ans = add(num1, num2)

print("Answer: ", ans)

elif op == "-":

ans = sub(num1, num2)

print("Answer: ", ans)

elif op == "*":

ans = mul(num1, num2)

print("Answer: ", ans)

elif op == "/":

ans = div(num1, num2)

print("Answer: ", ans)

else:

print("Please pick one from")

while_continue = input("Type yes to continue or no to exit")

if while_continue == "no":

running = False

if name == "__main__":

main()

# data[].attributes.body
def main():

running = True

while running:

num1 = int(input("Enter a number: "))

num2 = int(input("Enter a number: "))

op = input("Enter an operation(+ - * /): ")

if op == "+":

print("Answer: " , num1 + num2)

elif op == "-":

print("Answer: " , num1 - num2)

elif op == "*":

print("Answer: " , num1 * num2)

elif op == "/":

if num2 != 0:

print("Answer: " , num1 / num2)

else:

print("Cannot divide by zero")

else:

print("please choose from these operations + - * /")

will_run = input("Type yes to continue , Type no to stop: ")

if will_run == "no":

running =False

if name == "__main__":

main()

# data[].attributes.body
# let's start all the functions we will need

def add (x,y):

return x+y

def subtract (x,y):

return x-y

def mul (x,y):

return x*y

def div (x,y):

return x/y

# let's start writing our main function where we will make our calculator app

def main():

running = True

while running == True:

num1= int(input("Enter a number:"))

num2= int(input("Entera number:"))

op= input("Enter operation (*, +, /, -)):")

if op =="+":

ans=add(num1, num2)

print ("Answer:", ans)

elif op =="-":

ans= subtract(num1, num2)

print ("Answer:", ans)

elif op =="*":

ans= mul(num1, num2)

print ("Answer:", ans)

else:

if num2 == 0:

print ("Error: cannot divide by zero")

else:

ans= div(num1, num2)

print ("Answer:", ans)

will_continue = input ("Type yes to continue or no to exit:")

if will_continue == "no":

running = False

# data[].attributes.body
functions :

addition

Subtraction

Multiplication

Division

Cos , sin , tab

A while loop will be required for complex functions but basic functions can be done without the whole loop

Menu of operations to choose from

Defining the functions

Defining basic calculator logic

# data[].attributes.body
1. Functions:

Addition, subtraction, Multiplication, Division, Trigonometric functions e.t.c

2. loops are used to perform continuous functions and so that the user can input multiple functions. If the user puts an invalid value, then a loop can be used to make the user keep inputting values until they get a valid response.

3. first define the functions. user would input the information and then the specific functions required would be called and it would be run so that the output is displayed.

# data[].attributes.body
add, sub, multiply, divide, square root. Yes loops will be used in in this. Define the program, write a code add loops, and then check errors.

# data[].attributes.body
division, multiplication, addition,subtraction

trigonometric ratios

the square and cube roots

power , percentage and log functions

set values of pi and e

the app may need to run on loop itself unless it is turned off

it may also run on loop to input as many values as a function requires

# data[].attributes.body
1. basic operations: addition, subtraction, multiplication, division, trigonometric ratios, pi, roots and exponents, exception handing for division by 0 etc.

2. loops might be used but wouldn't be required for the other basic functions.

3. the functions would need to be defined, input would be taken from the user, the specific functions required would be called and then it would be run for the output to be displayed to the user.

# data[].attributes.body
1. addition, subrtaction, multiplication, divison, modulus, sqaure root,log

2. we use a while loop so that the calculator keeps asking for input everytime a calculation has been done, until it is switched off.

# data[].attributes.body
Zaynab Syed Mohsin

Functions:

addition

subtraction

multiplication

division

clear option

delete option

2) Loops would be needed as every person would enter numbers and do calculations.

3) I'm not so sure about it but first we would need to define and declare the functions and variables we would be using and put those in a loop so we can do calculations over and over again

# data[].attributes.body
1- addition, subtraction, division, multiplication, square root, cube root

2- code would run on a while loop

3- defining functions, asking for input, output answer

# data[].attributes.body
Functions:

-Addition

-Subtraction

-Multiplication

-Division

(Others include squares, roots, decimals, fractions)

Loops to be used for user input if it needs to be done multiple times

We will import math, define the functions, use loops, ask for input call the functions and so on

# data[].attributes.body
def add(x, y):

return x + y

def sub(x, y):

return x - y

def mul(x, y):

return x * y

def div(x, y):

return x / y

def main():

running = True

while running:

num1 = int(input("Enter number 1: "))

num2 = int(input("Enter number 2: "))

op = input("Enter operation(+ - * /):")

if op=="+":

ans = add(num1, num2)

print("Answer: ",ans)

elif op=="-":

ans = sub(num1, num2)

print("Answer: ",ans)

elif op=="*":

ans = mul(num1, num2)

print("Answer: ", ans)

elif op=="/":

if num2!=0:

ans = div(num1, num2)

print("Answer: ", ans)

else:

print("Error, division by 0")

else:

print("Please pick one from (+ - * /")

will_continue = input("Type 'yes'to continue and 'no' to exit")

if will_continue=="no":

running = False

if name == "__main__":

main()

# data[].attributes.body
Operators performed by cal: Addition, Subtraction, Division, Multiplication

Loops are used for repetitive tasks and iterating over data collections by repeating a block of code based on specific conditions like based on the operator used.

We receive inputs from the user and then, depending on the chosen operator, conditions are evaluated and the function is executed accordingly.

# data[].attributes.body
1. Addition

Subtraction

Multiplication

Division

2. use a loop in the beginning to make sure we get a valid response from the user or to get multiple responses

3. define functions then ask for user input and use the functions acc to the operations they select

# data[].attributes.body
1. We would definitely need some basic mathematical functions such as:

i) multiplication

ii) division

iii) subtraction

iv) addition

2. If the user has put an invalid value, then a loop can be used to prompt the user to keep on inputting c=values until he/she applies a valid input.

3. i) define the functions

ii) define calculator

iii) take input for the numbers

iv) apply the specific function required to the numbers

v) run the calculator

# data[].attributes.body
Q1:

the four basic operations:

division

multiplication

addition

subtraction

additionally:

trigonometric functions

exponential functions

logarithmic functions

inbuilt value of pi

etc

Q2: can be used for multiple values using list comprehension

Q3.

Take user input to use values

take user input for what is to be done for values

write code for basic functions

code to give value for task asked

print result

# data[].attributes.body
Amber Farooq

define functions for addition, subtraction, multiplication, division.

loops can be used to perform continuous functions until the user chooses to exit.

# data[].attributes.body
1. arithmetic functions

2. we can use loops if the user wants to repeat some output

# data[].attributes.body
1. functions for finding logs, square roots, or any other exponential functions. basic mathematical functions such as multiplication, division, addition and subtraction, trigonometric function etc.

2. loops are used to constantly prompt the user to input a number until the user decides to turn the calculator off.

# data[].attributes.body
1.) functions:

1. addition

2. subtraction

3. division

4. multiplications

2) Modules:

math module for: (square root, pi etc.)

3) exception handling (e.g. division by error)

4) The app would run off a while loop

num1=0

num2=0

while_continue=0

def addition_function(num1,num2):

return sum(num1,num2)

def subtraction_function(num1,num2):

return num1-num2

def multiplication_function(num1,num2):

return num1*num2

def division_function(num1,num2):

return num1/num2

def main():

ans=0

running=True

while running:

print("welcome to the calculator")

num1=int(input("Enter a number"))

num2=int(input("Enter another number"))

op=input("Enter opperation [+ - * /]")

if op=="+":

ans= addition_function(num1,num2)

print("Your answer is:",ans)

elif op=="-":

ans=subtraction_function(num1,num2)

print("Your answer is:",ans)

elif op=="*":

ans=multiplication_function(num1,num2)

print("Your answer is :",ans)

else:

try:

if num2!=0 and op=="/":

ans=division_function(num1,num2)

print("Your answer is:",ans)

except ZeroDivisionError:

print("You cant divide by zero")

else:

print("Invalid opperation")

will_continue=input("Do you want to continue? [y/n]")

print(will_continue)

if will_continue=="y":

running=True

elif will_continue=="n":

running=False

print("Program has ended")

if name == "__main__":

main()

# data[].attributes.body
Functions: we’ll be using various arithmetic operations such as addition, subtraction, division, multiplication, square root function by importing math and exponentiate numbers.

Loops: we can use a user input loop to continuously ask the user for various inputs like a while loop. We are also going to be requiring loops for handling invalid values as well as error handling loops(like checking for division with zero) until a valid value is provided.

Method:

We are going to define functions and operations and implement mechanisms to ask user for input, calculating using the required operations and asking the output to be displayed to the user. We can also add scientific functions like sin, cos,tan etc.

# data[].attributes.body
Addition subtraction multiplication division

We probably will need to use loops for error navigation

# data[].attributes.body
Functions:

Basic 4:

Addition

Subtraction

Multiplication

Division

More can be added (like exponents, roots, pi, trignometric ratios, etc.)

Loops:

The actual "app" itself would run off a while loop, so that the user can input multiple functions. Otherwise, most functions wouldn't need them

Method:

Define the functions.

Use a while loop to rerun the code.

Ask for inputs based on function being run

Output answer

Ask user if they want to try any more functions (if they say no, terminate the loop. if they say yes, restart.)

Code:

def add(num1, num2):

return num1 + num2

def subtract(num1, num2):

return num1 - num2

def multiply(num1, num2):

return num1 * num2

def divide(num1, num2):

try:

return num1 / num2

except ZeroDivisionError:

return("You tried to divide by 0!")

def main():

rerun_code = True

while rerun_code:

try:

operation = int(input("Enter a number: \n1. Add \n2. Subtract \n3. Multiply \n4. Divide \n"))

except ValueError:

print("Please enter a number!")

continue

if operation != 1 and operation != 2 and operation != 3 and operation != 4:

print("Please enter a valid number.")

continue

while True:

try:

num1 = int(input("Number 1: "))

num2 = int(input("Number 2: "))

except ValueError:

print("Please enter a number!")

continue

else:

break

if operation == 1:

print(add(num1, num2))

elif operation == 2:

print(subtract(num1, num2))

elif operation == 3:

print(multiply(num1, num2))

elif operation == 4:

print(divide(num1, num2))

rerun = input("Do you want to do another calculation? (Y/N) \n")

if rerun.lower() == "y":

rerun_code = True

elif rerun.lower() == "n":

rerun_code = False

else:

print("Please enter Y or N.")

if __name__ == "__main__":

main()

# data[].attributes.body
Addition

Subtraction

Multiplication

Division

Clear

Decimal

Evaluate Expression

LOOPS:

We may have a loop that continuously waits for user input until they choose to exit the program.

Include different components like number buttons, operator buttons, clear buttons, and an equals button. The interface should be intuitive and user-friendly, facilitating easy input and interaction

# data[].attributes.body
Subtraction

Addition

Multiplication

Division

Trignometric functions

We can use loops so that the user can perform multiple functions

We will import math, define functions and ask for input and then return output and so on.

# data[].attributes.body
Square, cube root, logs

# data[].attributes.body
add, subtract,multiply,divide

sin cos tan

value of π

using percentage

# data[].attributes.body
1. Functions:

Addition

Subtraction

Multiplication

Division

(others for a complex calculator: squares, cubes, roots etc)

2. We can use loops to get more inputs or run the program again and again

3. -Define all of the functions

-Add the two variable numbers and assign them the two user input numbers

-Take input from user, can be in for of 1.Add, 2. Subtract etc

-Use if-else statements to see if input is equal to 1,2, 3 or 4 using ==

-Output final ans using print statement

4. Code:

def addtion(num1,num2):

add= num1+ num2

return add

def subtraction(num1,num2):

sub= num1-num2

return sub

def multiply(num1,num2):

mul= num1*num2

return mul

def divide(num1,num2):

div= num1/num2

return div

def main():

cont= True

while cont==True:

num1=int(input("Enter the 1st number: "))

num2=int(input("Enter the 2nd number: "))

func = input("Enter operation +,-,*,/: ")

if func=="+":

print("Answer: ", addtion(num1,num2))

elif func=="-":

print("Answer: ", subtraction(num1,num2))

elif func=="*":

print("Answer: ", multiply(num1,num2))

elif func=="/":

if num2!=0:

print("Answer: ", divide(num1,num2))

else:

print("Zero Error, can't divide by zero")

else:

print("Invalid operation. Please input a valid operation")

will_cont= input("Type yes to continue or Type no to exit ")

if will_cont=="yes":

cont=True

else:

cont=False

main()

# data[].attributes.body
1. addition

subtraction

multiplication

division

2. we can use loops for if the user needs to do calculations multiple times

# data[].attributes.body
1. Add, subtract,multiply and divide real numbers, integers and fractions, decimals. Exception handling for division by 0 for example.

2. Loop for checking sensible input values eg to ensure that a number is entered.

3. Define functions

• while loop to rerun the code

• Ask for inputs

• Choice of function

• output result

• Ask for more function otherwise terminate the loop.

# data[].attributes.body
1. What functions will you need for your calculator app?

2. Do you need to use loops anywhere?

3. How will you go about your code (brief plan)?