Python Forum
how to get the value out the def function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to get the value out the def function
#1
Error:
Error : print(choice_cost + car_cost) NameError: name 'choice_cost' is not defined
thank you

"""Total Car Cost"""

car_cost = 500

def total_cost():
    print(choice_cost + car_cost)


def color_cost():
    print()
    print("For Blue Enter 1.","For Red Enter 2" )
    print()
    choice = int(input("Please enter color choice :"))
    if choice == 1:
        choice_cost = 100
        total_cost()
    elif choice == 2:
        choice_cost = 200
        total_cost()
    else:
        print("Invalid Choice. Please choose again")
    color_cost()

color_cost()
Reply
#2
Use return.
Example
def some_function(input_value):
    what_to_return = input_value + 100
    return what_to_return

returned_value = some_function(10)
print(f'Returned value: {returned_value}')
Output:
Returned value: 110
Reply
#3
Thank you so much
Reply


Forum Jump:

User Panel Messages

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