Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
new to coding
#1
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 )
Reply
#2
(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.
Reply
#3
And note that Python is case sensitive. It's 'return' not 'Return' and 'print' not 'Print'.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
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 )
I am trying to help you, really, even if it doesn't always seem that way
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020