V
V
Vadim kyklaed2015-03-30 18:23:22
Python
Vadim kyklaed, 2015-03-30 18:23:22

I wrote a small program, and I want to break it into modules, why does the block of calculations not work?

Good evening, I have such a question, I wrote a program and wanted to break it into modules (I'm just learning to program), the point is that the calculation block is not processed, below I have given the code of each block. python 3.4
I am writing a small such calculator with writing the result to a file, in order to select an action on numbers, you must enter a number, the program compares in the processing block, if the numbers converge, then the calculation occurs, if not, then fail.
So the problem is this - the value for comparison is not processed or passed, and the values ​​​​over which the actions take place are transferred normally
pastie.org/10062892
import inputvalue
import calculatingresult
FILE_NAME = 'data.txt'
#print("select the action and enter the number of action in the field = 1 - addition,")
#print("2 - subtraction, 3 - Multiply, 4 - division, 5 - involution")
value = inputvalue.input_value( int,"number of action","message_error")
digit = inputvalue.input_value(float,"enter the first number","message_error")
digit2 = inputvalue.input_value(float, "Enter the second number: ", "message_error2" )
calculatingresult.calculating_saving_result (digit,digit2)
pastie.org/10062895
import calculatingresult
def input_value(type_value, message, message_error):
while True:
try:
return type_value(input(message))
except (TypeError, ValueError):
print(message_error)
pastie.org/10062896
import inputvalue
FILE_NAME = 'data.txt'
def calculating_saving_result (r_digit, r_digit2):
file_calculation = open (FILE_NAME, 'a')
print(r_digit, r_digit2)
if inputvalue.input_value==1:
r_addition = r_digit + r_digit2
file_calculation.write (str(r_addition))
elif inputvalue.input_value==2:
r_subtracting = r_digit - r_digit2
file_calculation.write (str(r_subtracting))
elif inputvalue.input_value==3:
r_multiplication = r_digit * r_digit2
file_calculation .write(str(r_multiplication))
elif inputvalue.input_value==4:
r_division = r_digit / r_digit2
file_calculation.write (str(r_division))
elif inputvalue.input_value==5:
r_involution = r_digit ** r_digit2
file_calculation.write (str(r_involution))
else:
file_calculation.write ('fail')
#print("fail")
file_calculation.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Samoilov, 2015-03-30
@Nitive

inputvalue.input_value is a function

print(inputvalue.input_value)
<function input_value at 0x10b007950>

Therefore, the contents of the else block will always be executed - You need to pass value to file_calculation.write ('fail')
the function calculating_saving_result(), and already work with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question