Use Python progrmaing Esther Mates favorite subject at schoo
Use Python progrmaing.
Esther Mate\'s favorite subject at school has always been mathematics. She asks you to write a script (called calculator.py) that:
takes in two integers that are both between 0 and 100.
takes in an operator to operate on the integers.
prints the first error encountered then does not continue execution.
Errors include:
either of the integer values is not between 0 and 100.
the operator is not of the type: +, -, *, /, //, %, **
prints the correct calculation if the two integers and the operator are all valid.
For example
Hint: The operator will be coming in as a string, and you cannot use it directly in computations. You will need to determine if the string operator is one of the valid operators using conditional statements.
Be sure your program\'s output matches the above screenshot (the errors triggered and the order of questions asked) to receive the most points.
What is the first integer value? 0 What is the second integer value 100 What operation are you performing? The first integer value is invalid. RESTART What is the first integer value? 99 What is the second integer value? 100 What operation are you performing? The second integer value is invalid RESTART What is the first integer value? 45 What is the second integer value 34 What operation are you performing? You entered an invalid operator RESTART What is the first integer value? 12 What is the second integer value? 102 What operation are you performing? The second integer value is invalid RESTART What is the first integer value? 3 What is the second integer value 45 What operation are you performing? Answer: 295 1312 706550833698 643Solution
while True:
x = int(input(\"What is the first integer value?: \"))
y = int(input(\"What is the second integer value?: \"))
operator = raw_input(\"What operation are you performing?: \")
#check if x and y value are between 0 and 100
if x <= 0 or x >= 100:
print(\'first integer value is invalid\')
continue
if y <= 0 or y >= 100:
print(\'second integer value is invalid\')
continue
#depending on the operator enterd perform desired operation
if operator == \'+\' :
print \"Answer = \",x+y
break
if operator == \'-\' :
print \"Answer = \",x-y
break
if operator == \'*\' :
print \"Answer = \",x*y
break
if operator == \'/\' :
print \"Answer = \",x/y
break
if operator == \'%\' :
print \"Answer = \",x%y
break
if operator == \'**\' :
print \"Answer = \",x**y
break
if operator == \'//\' :
print \"Answer = \",x//y
break
else :
print \"You entered invalid operator \"
continue
--------------------------------------------------------------------------------------------------
output:
What is the first integer value?: 0
What is the second integer value?: 100
What operation are you performing?: +
first integer value is invalid
What is the first integer value?: 99
What is the second integer value?: 100
What operation are you performing?: *
second integer value is invalid
What is the first integer value?: 45
What is the second integer value?: 34
What operation are you performing?: ?
You entered invalid operator
What is the first integer value?: 12
What is the second integer value?: 102
What operation are you performing?: >
second integer value is invalid
What is the first integer value?: 3
What is the second integer value?: 45
What operation are you performing?: **
Answer = 2954312706550833698643

