mercredi 8 février 2017

unsupported operand type(s) for +: 'function' and 'function'

I want to first say this is my homework, so I do not want it done for me I just need some guidance as my teacher is not providing it for me nor can I find my answer online. Here is my problem

Write a program that displays a table of distance equivalents in miles and kilometers. See Example output. You must generate the table by running a function inside a loop in main. Generate a random integer from 10 to 60, inclusive, in each loop cycle. Use this latter value as the miles argument to the function. The function must then print a line in the table. Repeat: The function prints the table. Use the formatting concepts at the end of Chapter 2 to print columns with width and decimal control as shown. Example output

MILES KILOMETERS 52.00 83.68568 11.00 17.70274 40.00 64.37360 21.00 33.79614 14.00 22.53076 23.00 37.01482 48.00 77.24832 22.00 35.40548 15.00 24.14010 16.00 25.74944

my code

import random

def main():
    miles()
    klm()
    print('milesg\tklms')

 #random number of miles  
def miles():

    for count in range(10):
        milesg = random.randint(10, 60)

        return milesg


  #the conversion too kilometers      
def klm():
    conversion = 1.60934

    klm = conversion + miles

    return klms
main()

my error message Traceback (most recent call last): File "C:/Users/brittmoe09/Desktop/program5_1.py", line 24, in <module> main() File "C:/Users/brittmoe09/Desktop/program5_1.py", line 5, in main klm() File "C:/Users/brittmoe09/Desktop/program5_1.py", line 21, in klm klm = conversion + miles TypeError: unsupported operand type(s) for +: 'float' and 'function'




Aucun commentaire:

Enregistrer un commentaire