Error name variable is not defined?

In General, I'm just starting to learn to write in Python, but I have a problem writing your first code, I got error, if I wrote a simple calculator for all actions, all actions are working perfectly, but there is a problem with rounding when I have rounded a number, everything is done(works), but when I do another action, for example addition, it is also done, the numbers add up amount is displayed, but gives error related to rounding, supposedly can't find variable, but again, when the number round everything works perfectly

from math import ceil as okrb
from math import floor as okrm
print(' Hello you got the app "calculator v Debility.1" ')
print(' I want to introduce you its functions, are you ready? ')
otvet = input(" If you're ready - then write yes! ")
if otvet == "yes":
 print(" Wow, well look. I know how to add, subtract, multiply, divide numbers. ")
 print( " Well, I also know how to build them in the degree of rounding. ")
otvet2 = input(" Here are my commands: addition, subtraction, division, multiplication, exponent, rounding. Choose! ")
if otvet2 == "addition":
 a = float(input("Okay, then I enter the number to which we must add: "))
 b = float(input("Okay, fill me the number which we must add: "))
 c = a + b
 print(" Response: "+ str(c))
if otvet2 == "subtraction":
 a = float(input("Okay, then I enter the number from which to subtract:: "))
 b = float(input("Okay, fill me the number that should be subtracted: "))
 c = a - b
 print(" Response: "+ str(c))
if otvet2 == "fission":
 a = float(input("Okay, then I enter the number that we need to divide: "))
 b = float(input("Okay, fill me the number by which we divide: "))
 c = a / b
 print(" Response: "+ str(c))
if otvet2 == "multiply":
 a = float(input("Okay, then I enter the number that should be multiplied: "))
 b = float(input("Okay, fill me a number by which to multiply: "))
 c = a * b
 print(" Response: "+ str(c))
if otvet2 == "degree":
 a = float(input("Okay, then I enter the number which is necessary to build in a degree: "))
 b = float(input("Okay, fill me a number on how much we build in degree: "))
 c = a ** b
 print(" Response: "+ str(c))
if otvet2 == "rounding":
 print(" Okay, then tell me where I should round up your number. In the big or little.")
 side = input(" If you need to round a number in a big way, then write okrb, if a little okrm: ")
if side == "okrb":
 a = float(input(" Okay, enter the number I need to round: ")) 
 otvetokr1 = okrb(a)
 print(" Here is the number I got: "+ str(otvetokr1))
if side == "okrm":
 a = float(input(" Okay, enter the number I need to round: "))
 otvetokr2 = okrm(a)
 print(" Here is the number I got: "+ str(otvetokr2))


5e4906cfdbf46597779554.png
5e4906dc800de077953858.png
April 7th 20 at 15:16
1 answer
April 7th 20 at 15:18
Solution
Because the variable side is determined only when this condition is true:
if otvet2 == "rounding":
 print(" Okay, then tell me where I should round up your number. In the big or little.")
 side = input(" If you need to round a number in a big way, then write okrb, if a little okrm: ")

define the variable outside the block above:
side = None
if otvet2 == "rounding":
 print(" Okay, then tell me where I should round up your number. In the big or little.")
 side = input(" If you need to round a number in a big way, then write okrb, if a little okrm: ")

Find more questions by tags Python