#Other Miscellaneous Improvements
Other Miscellaneous Improvements
#Other Miscellaneous Improvements
Other Miscellaneous Improvements
def main():
isum1 = 0
isum2 = 0
isum3 = 0
totalSumisum1 = 0getValue()
isum2 = getValue()
isum3 = getValue()
itotal = getProd(isum1, isum2, isum3)
displayProductData(isum1, isum2, isum3, itotal)
#Other Miscellaneous Improvements
The Python style guide suggests using lower_case_with_underscores when naming variables and functions, rather than mixedCase.
def get_value():
#code
def get_sum():
#code
def get_prod()
Within functions, it is possible to directly return an expression, without having to assign it to a variable first.
def get_sum(first, second):
return first + second
def get_prod(n1,n2,n3):
return n1 * n2 * n3
In main, you write that you "need to initialize the needed variables", but in fact you do not have to do that at the beginning of a function! You can assign to a variable wherever you want. Just don't attempt to use a variable that hasn't been defined yet.
def main():
isum1 = getValue()
isum2 = getValue()
isum3 = getValue()
itotal = getProd(isum1, isum2, isum3)
displayProductData(isum1, isum2, isum3, totalSumitotal)
If you are using Python 2 and not Python 3, then print doesn't require parentheses. In fact, the output may look better as a result, since without parentheses it won't interpret your expression as a tuple.
def display_product_data(first, second, third, total):
print "The first value is = ", first
print "The second value is = ", second
print "The third value is = ", third
print "The Total is = ", total
The output used to be:
('The first value is = ', 2.0)
('The second value is = ', 3.0)
('The third value is = ', 4.0)
('The Total is = ', 24.0)
Now it is:
The first value is = 2.0
The second value is = 3.0
The third value is = 4.0
The Total is = 24.0
You don't need to use semicolons. They're just there to make users comfortable when coming from other languages. And to delimit multiple statements on one line, but that's not very common.
def main():
isum1 = 0
isum2 = 0
isum3 = 0
totalSum = 0
isum1 = getValue()
isum2 = getValue()
isum3 = getValue()
itotal = getProd(isum1, isum2, isum3)
displayProductData(isum1, isum2, isum3, totalSum)
def main():
isum1 = 0
isum2 = 0
isum3 = 0
isum1 = getValue()
isum2 = getValue()
isum3 = getValue()
itotal = getProd(isum1, isum2, isum3)
displayProductData(isum1, isum2, isum3, itotal)
#Other Miscellaneous Improvements
The Python style guide suggests using lower_case_with_underscores when naming variables and functions, rather than mixedCase.
def get_value():
#code
def get_sum():
#code
def get_prod()
Within functions, it is possible to directly return an expression, without having to assign it to a variable first.
def get_sum(first, second):
return first + second
def get_prod(n1,n2,n3):
return n1 * n2 * n3
In main, you write that you "need to initialize the needed variables", but in fact you do not have to do that at the beginning of a function! You can assign to a variable wherever you want. Just don't attempt to use a variable that hasn't been defined yet.
def main():
isum1 = getValue()
isum2 = getValue()
isum3 = getValue()
itotal = getProd(isum1, isum2, isum3)
displayProductData(isum1, isum2, isum3, itotal)
If you are using Python 2 and not Python 3, then print doesn't require parentheses. In fact, the output may look better as a result, since without parentheses it won't interpret your expression as a tuple.
def display_product_data(first, second, third, total):
print "The first value is = ", first
print "The second value is = ", second
print "The third value is = ", third
print "The Total is = ", total
The output used to be:
('The first value is = ', 2.0)
('The second value is = ', 3.0)
('The third value is = ', 4.0)
('The Total is = ', 24.0)
Now it is:
The first value is = 2.0
The second value is = 3.0
The third value is = 4.0
The Total is = 24.0
You don't need to use semicolons. They're just there to make users comfortable when coming from other languages. And to delimit multiple statements on one line, but that's not very common.
Your getProd is a good start, but you have to return something for it to be useful.
def getProd(n1,n2,n3):
itotal = n1 * n2 * n3
return itotal
displayData isn't suitable for displaying product data, since it mentions a "total" and has only two variables. You could write another method with similar behavior, however:
def displayProductData(first, second, third, total):
print("The first value is = ", first);
print("The second value is = ", second);
print("The third value is = ", third)
print("The Total is = ", total);
Lastly, you need to update your main so that it properly uses the new method.
def main():
isum1 = 0
isum2 = 0
isum3 = 0
totalSum = 0
isum1 = getValue()
isum2 = getValue()
isum3 = getValue()
itotal = getProd(isum1, isum2, isum3)
displayProductData(isum1, isum2, isum3, totalSum)