Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
new to coding
#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


Messages In This Thread
new to coding - by abdullahali - Sep-23-2018, 04:40 AM
RE: new to coding - by Gribouillis - Sep-23-2018, 05:28 AM
RE: new to coding - by ichabod801 - Sep-23-2018, 01:33 PM
RE: new to coding - by gruntfutuk - Sep-30-2018, 01:49 PM

Forum Jump:

User Panel Messages

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