Commit cf63888d by likorn

catched some errors

parent 2c4ea41b
Showing with 22 additions and 11 deletions
......@@ -7,7 +7,13 @@ def input_float(text):
try:
float(inp)
except ValueError:
return input_float(text)
try:
complex(inp)
except:
return input_float("It's not a number, try again: ")
return input_float(
"It seems that you're trying to enter a complex number, unfortunately we don't support them. "
"Try again: ")
return float(inp)
......@@ -17,7 +23,11 @@ def input_with_conditions(text, operator):
# since we'll need to divide by A I also added A != 0 to prevent the errors
error_msg = "The value doesn't fit the conditions, try again "
value = input_float(text)
if (operator == '>' and value <= 0) or (operator == '>=' and value < 1) or (operator == '!=' and value == 0):
if (operator == '>' and value <= 0) or (operator == '>=' and value < 1):
return input_with_conditions(error_msg, operator)
elif operator == '!=' and value <= 0:
error_msg = "Hey, sorry, we'll have to divide by A and get the square root of it, so all of the values less " \
"or equal to 0 are unacceptable "
return input_with_conditions(error_msg, operator)
return value
......@@ -25,8 +35,8 @@ def input_with_conditions(text, operator):
def calculate_x(until):
# calculate x in the necessary points
xx = a + h
for i in range(1, until+1):
xx = xx + h*math.pow(c, i)
for i in range(1, until + 1):
xx = xx + h * math.pow(c, i)
return round(xx, 3)
......@@ -53,20 +63,21 @@ h = input_with_conditions("Enter a step H = ", '>')
c = input_with_conditions("Enter the step's coefficient C = ", '>=')
ym = input_float("Enter function value upper limit YM = ")
x = []
y = []
x.append(round(a, 3))
y.append(calculate_y(a))
x.append(round(a + h, 3))
y.append(calculate_y(a + h))
if calculate_y(a) <= ym:
x.append(round(a, 3))
y.append(calculate_y(a))
if calculate_y(a + h) <= ym:
x.append(round(a + h, 3))
y.append(calculate_y(a + h))
counter = 1
while counter < 14:
x.append(calculate_x(counter))
y.append(calculate_y(calculate_x(counter)))
counter += 1
if not y[len(y)-1] <= ym:
y.remove(y[len(y)-1])
if not y[len(y) - 1] <= ym:
y.remove(y[len(y) - 1])
break
print_table()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment