On 2015-09-24 19:45, codyw...@gmail.com wrote:
I seem to be having a problem understanding how arguments and parameters work,
Most likely why my code will not run.
Can anyone elaborate on what I am doing wrong?
'''
Cody Cox
9/16/2015
Programming Exercise 1 - Kilometer Converter
Design a modular program that asks the user to enter a distance in kilometers
and then convert it to miles
Miles = Kilometers * 0.6214
'''
First of all, it looks like your indentation is slightly off because
"def main" line is that the left margin and the other 2 "def" lines and
the "main()" line aren't.
def main():
You're not passing anything into 'get_input', neither are you saving
any result that it might be returning.
get_input()
You're not passing anything into 'convert_kilo'.
convert_kilo()
You're defining 'get_input' to accept 1 parameter 'kilo'. Why? You're
assigning to 'kilo' in the first line, so any value you _did_ pass in
would be ignored.
def get_input(kilo):
kilo = float(input('Enter Kilometers: '))
return kilo
You're defining 'convert_kilo' to accept 2 parameters. You're using the
'kilo' parameter, but not the 'miles' parameter because you're
assigning to it on the first line, so any value you _did_ pass in would
be ignored.
def convert_kilo(kilo,miles):
'kilo' is already a float, and you're multiplying it by a float, so the
'float' call is pointless.
miles = float(kilo * 0.6214)
print( kilo,' kilometers converts to ',miles,' miles')
main()
--
https://mail.python.org/mailman/listinfo/python-list