Lab Assignment #4

Adding Exponential Numbers


Description
In this assignment, I will explain the codes I used to add two exponential numbers. I used some of Python’s calculator code to help run the program correctly. The user must enter three sets of numbers upon the program’s request. The program will calculate the results and display the answer on the screen. If the user enters any non-integers (non-numbers), an error message will appear and the user must restart the program, enter integers to see their results .


Code
a = int(raw_input(‘enter first number: ‘))
b = int(raw_input(‘enter second number: ‘))
exp = int(raw_input(‘enter exponential number: ‘))
result = a**exp + b**exp
print(a**exp ,’+’ ,b**exp ,’=’ , result)


Code Description
Line 1 – 3, I used the code ‘int(raw_input)‘ so that the program will accept only integers. Any non-integers will not satisfy the program and will cause an error. Also in line 1 – 3. I named the variables a, b, and exp for mathematical purposes. Inside the parameters (‘‘), the statement will display a message on the screen.

Line 4: The variable ‘result‘ is assigned to equation I chose for the program. The double asterisk (**) means exponents in Python.

Line 5: The print statement will display the answer on the screen.


Result
adding exponential numbers