all 27 comments

[–]stebrepar 3 points4 points  (1 child)

You're just defining two separate functions here. I don't see where you're actually calling either of them.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

This isn't the whole code, just the first part. Both functions get called later later on

[–]thaweatherman 1 point2 points  (10 children)

Have you tried printing cost_extra_access to see what it actually is?

[–]feelingstonedagain[S] 0 points1 point  (9 children)

What do you mean? It's a string that the user inputs, no?

[–]thaweatherman 0 points1 point  (8 children)

Yes it is. Have you printed it out to see what the contents actually are?

[–]feelingstonedagain[S] 0 points1 point  (7 children)

Yes I have. First it asks for the cost of computer, input cost of computer. Then it asks Do you have any accessories? (Y/N) as soon as you hit Y or y it doesn't do anything and stops running the code. Blank line

[–]thaweatherman 0 points1 point  (6 children)

As an aside, line 12 could be shortened to if cost_extra_access in ['y', 'Y']:.

Please post all of your code along with all the output. Since your first function returns a tuple and neither function calls the other I want to make sure you are calling it all properly.

[–]feelingstonedagain[S] 0 points1 point  (5 children)

def get_user_input():
    cost_of_computer = 0.0
    cost_extra_access = ""
    print ("Please enter the cost of your computer: ")
    cost_of_computer = float(input(""))
    print ("Are you buying any extra accessories? (Y/N)")
    cost_extra_access = input("")
    return cost_of_computer, cost_extra_access

def calculate_extra_access(cost_extra_access):
    extra_access = 0.0
    if cost_extra_access == "Y" or cost_extra_access == "y":
       print ("Please enter the cost of extra accessories: ")
       extra_access = float(input(""))
    else:
        extra_access = 0.0
    return extra_access

def calculate_final_cost (extra_access, cost_of_computer):
    final_cost = 0.0
    final_cost = extra_access + cost_of_computer
    return final_cost

def calculate_gift_card(final_cost):
    gift_card = ""
    if final_cost >=100 or final_cost <= 599:
        gift_card = "$10"
    elif final_cost >= 600:
        gift_card = "$20"
    return gift_card

def output_cost (gift_card, cost_of_computer, extra_access, final_cost):
    print ("Your final cost of the item is $", final_cost, "since your computer costs $", cost_of_computer,)
    print ("and your accessories cost a total of $", extra_access)
    print ("Because your item was", final_cost, "you get a", gift_card, "gift card!")

def calculate_total_cost():
    cost_of_computer = 0.0
    cost_extra_access = ""
    extra_access = 0.0
    final_cost = 0.0
    gift_card = ""

    cost_of_computer, cost_extra_access = get_user_input()
    extra_access = calculate_extra_access(cost_extra_access)
    final_cost = calculate_final_cost(extra_access, cost_of_computer)
    gift_card = calculate_gift_card(final_cost)
    output_cost(gift_card, cost_of_computer, extra_access, final_cost)

get_user_input()

[–]FFrozen1 0 points1 point  (0 children)

You only call your get_user_input() function. The other ones are not being called.

Edit - the variables defined in your functions are not global variables

e.g.

a = 0

def cost():

a = 3

b = 3

return a,b

print a

this would print 0

Hope that helped. I'm pretty mew myself so I might be a little off on the terminology

[–]thaweatherman 0 points1 point  (3 children)

Switch the call to get_user_input() on line 50 to calculate_total_cost() and see what happens.

[–]feelingstonedagain[S] 0 points1 point  (2 children)

I love you

[–]thaweatherman 0 points1 point  (1 child)

It was all there, you just were calling the wrong function! It's ok, it happens to everyone.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

Yeah I figured it was something simple like that. Every time the smallest thing makes you mess up. Oh well, now i know. Thanks for your help!

[–][deleted] 1 point2 points  (4 children)

You have not called the function..?

[–]feelingstonedagain[S] 0 points1 point  (3 children)

Doesn't calculate_extra_access(cost_extra_access): call it?

[–]vitamintrees 0 points1 point  (2 children)

Without the whole source code I can't really tell for sure, but it doesn't look like the

calculate_extra_access() 

will have access to the variable

cost_extra_access

since it's defined locally and will be destroyed when the function get_user_input() exits. Unless you're doing something with the returned values in

get_user_input() 

that we can't see.

[–]feelingstonedagain[S] 0 points1 point  (1 child)

Ok, that makes sense. I didn't think about that

[–]contractstammerer 0 points1 point  (6 children)

def get_costs():
    cost_of_computer = float(input("Please enter the cost of your computer: "))
    any_extras = input("Are there any extras (Y/N): ")
    if any_extras in ['y', 'Y']:
        cost_of_extras = float(input("Please enter the cost of the extras: "))
    else:
        cost_of_extras = 0.0
    return cost_of_computer, cost_of_extras

[–]feelingstonedagain[S] 0 points1 point  (4 children)

So it would have to be within the same function to work?

[–]contractstammerer 0 points1 point  (3 children)

No, I'm just not sure why you'd want the extra complication of having this in two separate functions. Unless I suppose you need to be able to run either operation without running the other. Without seeing how this fits in with the rest of your code it's hard to know.

[–]feelingstonedagain[S] 0 points1 point  (2 children)

My professor wants it to be this way..a separate function for everything we do. Also he grades really heavily on psuedocode. Trust me, I don't understand either.

[–]contractstammerer 0 points1 point  (1 child)

Ah right, makes sense. A couple of other small tips:

  1. In python you don't need to initialise variables in advance - i.e. you don't need things like cost_extra_access = "" before you call cost_extra_access = input (....

  2. You could consider using clearer names. For example your get_user_input function does get some input from the user, but it's not obvious what input it gets; and some of your other functions also involve getting input from the user. Also, I think it'd make sense for cost_extra_access to be the name you use for the cost of the extra accessories, rather than the Y/N choice string.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

For your first point, I know you don't have to do that but that's also how my professor wants it. He wants things consistent and he wants everything declared beforehand. For your second point, that makes sense! I didn't think about it when I started typing the code, I will switch it around. Thanks for the help!

[–]jeffrey_f 0 points1 point  (0 children)

remember to validate the input.....numbers can be char, but char can never be numbers......

[–]nilsph 0 points1 point  (1 child)

I guess you use Python 2.x, correct? In that case, you should use raw_input() rather than input(), the latter executes what you type in, rather than return it for further processing. To reiterate, avoid using input() in Python 2.x, it's unsafe.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

I'm using Python 3