Python Forum
new to coding - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: new to coding (/thread-12997.html)



new to coding - abdullahali - Sep-23-2018

Hello, I am trying to write a program that reads the user’s fuel used and distance travelled from the console, passes
the entered values to the fuel_efficiency function to perform the computation, obtains the function’s
return value, and then prints a message to the console that reports the user’s fuel eciency rating. My code is not working past the return part, anyhelp appreciated


fuel_used = Int(Input(“fuel used: “))
distance_travelled = int(input(“distance travelled: “))
fuel_efficiency = (“fuel_used / distance * 100: “)
Return fuel_efficiency
Print(“fuel efficiency rating of a car that uses”, fuel_used, “liters, and travels”, distance_travelled, “km is”, fuel_efficiency )


RE: new to coding - Gribouillis - Sep-23-2018

(Sep-23-2018, 04:40 AM)abdullahali Wrote: My code is not working past the return part, anyhelp appreciated
The best help comes from the error message sent py the python interpreter. Please post this exception traceback in its entirety and use BBcode syntax to post code and errors.


RE: new to coding - ichabod801 - Sep-23-2018

And note that Python is case sensitive. It's 'return' not 'Return' and 'print' not 'Print'.


RE: new to coding - gruntfutuk - Sep-30-2018

return is only used in a function to return some value(s) to wherever the function was called from, e.g.

def powerof2(num):
    some_calc = num ** 2
    return some_calc

answer = powerof2(5)
print(answer)
When I copied your code, the quotes were speech marks rather than Python required straight double-quotes (make sure your editor/os is not being helpful and replacing the quotes for you.

You are inconsistent when referring to the distance variable, calling it by two different names.

Your calculation of fuel efficiency had the variables for the calculation in quotes, so Python would think they were strings rather than variables.

Some of your Python code was Title cased, such as Int and Integer, which would not be valid.

Corrected code:

fuel_used = int(input("fuel used: "))
distance_travelled = int(input("distance travelled: "))
fuel_efficiency = fuel_used / distance_travelled * 100
print("fuel efficiency rating of a car that uses", fuel_used, "liters, and travels", distance_travelled, "km is", fuel_efficiency )