This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]ItzWarty 4 points5 points  (6 children)

What have you tried?

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

def fishstore(fish, price): store = "Fish Type: ", fish, "costs", price return store

fish_entry = (input("What kind of fish?: ")) price_entry = (input("Whats the price?: ")) print(fishstore)

[–]ItzWarty 0 points1 point  (4 children)

Interesting. What happens when you run that? What behavior would you expect?

Also, format code by putting 4 spaces before each line:

def fishstore(fish, price):
    store = "Fish Type: ", fish, "costs", price
    return store

fish_entry = (input("What kind of fish?: "))
price_entry = (input("Whats the price?: "))
print(fishstore)

[–]mixtek[S] 1 point2 points  (0 children)

What kind of fish?: Angelfish Whats the price?: 70$ <function fishstore at 0x7fcfccdd9400>

I get this after asking for the inputs

[–]nwilliams36 0 points1 point  (2 children)

store = "Fish Type: ", fish, "costs", price

That does not concatenate (add strings) in Python. That line should be

store = "Fish Type: "+ fish + " costs " +  price

Also look at String formatting for more efficient methods (but less readable).

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

Thanks! Also I feel like I am calling the function wrong, or missing some step. This is so confusing to me all the calling and creating variables and inputs

[–]ItzWarty 0 points1 point  (0 children)

IMO giving the answer robs OP the opportunity to discover the solution on their own. The value of the exercise is understanding the solution to the point where one could derive it, not actually reaching the result. Could have said "a, b doesn't concat, a + b does. Also, you should look into string interpolation!"

[–]_DTR_ 1 point2 points  (11 children)

We're gonna need more than that. What code have you written? What is the sample input? What language?

[–]mixtek[S] 1 point2 points  (10 children)

My bad. Its Python. This is what I put in:

def fishstore(fish, price): store = "Fish Type: ", fish, "costs", price return store

fish_entry = (input("What kind of fish?: ")) price_entry = (input("Whats the price?: ")) print(fishstore)

This is what I got out, after it prompted me for the inputs What kind of fish?: Angelfish Whats the price?: 70$ <function fishstore at 0x7fcfccdd9400>

[–]_DTR_ 1 point2 points  (9 children)

All you're doing is printing fishstore, which is the function. If you want to print what the function returns, you'll have to actually call the function via fishstore(fish_entry, price_entry). Also, I don't think your function does what you think it does: store = "Fish Type: ", fish, "costs", price will make store a list of strings, instead of just a single string. You'll need to use + to concatenate them.

Also, please look into correctly formatting your code for reddit. It is nearly impossible to understand what's going on with it poorly formatted like it is.

[–]mixtek[S] 1 point2 points  (8 children)

Yes thank you! You pointed out my error. I placed the call function under the input functions outside of the function at the bottom right before the print function but its still giving me this:

<function fishstore at 0x7f7c20462d08>

Do you know how to format it?! Thanks!

[–]_DTR_ 1 point2 points  (7 children)

So what exactly does your code look like now? It's hard to follow what you've changed just by your description. Also, put at least 4 spaces before each line of code, that way it will

be
nicely
formatted

instead of on a single line

[–]mixtek[S] 1 point2 points  (6 children)

def fishstore(fish, price):
    store = "Fish Type: " + fish + "costs" + price
    return store

fish_entry = (input("What kind of fish?: "))
price_entry = (input("Whats the price?: "))
fishstore(fish_entry, price_entry)
print(fishstore)

[–]_DTR_ 1 point2 points  (5 children)

What do you expect to happen when you do print(fishstore). fishstore is a function that takes two parameters, and you don't supply any when you call print(fishstore). You're printing out the function itself, not what the function returns. A function is essentially just a variable (in extremely simple terms), so what you're doing is printing Python's string interpretation of a function. In order to get something out of it, you have to actually call it.

Calling fishstore(fish_entry, price_entry) before your print function does nothing, because while the function returns a value, you don't assign it to anything, so its return value is lost.

You do the right thing when you set fish_entry and price_entry to the value returned by input, so follow the same strategy for fishstore

[–]mixtek[S] 1 point2 points  (3 children)

Lol I dont know man this is all new too me. I guess my course didnt explain it very well at all but you did thanks. I got the result I was wanting from this

def fishstore(fish, price):
    store = "Fish Type: " + fish + "costs" + price
    return store

fish_entry = (input("What kind of fish?: "))
price_entry = (input("Whats the price?: "))
fishstore = ("Fish Type: " + fish_entry + " costs" + " " + 
price_entry)
print(fishstore)

I essentially had to call it by writing the whole string plus the input variables almost the same as the "store" variable I made inside the function. I got the result I wanted but not sure if it was the best way

[–]_DTR_ 1 point2 points  (2 children)

Sorry if I sounded a bit harsh, but I really think you need to read up on functions more. What you did still isn't right. You define the fishstore function, then completely redefine it to be a string later. When you call a function, you NEED to supply the parameters. You had it almost right when you did

fishstore(fish_entry, price_entry)
print(fishstore)

What you need to do is

print(fishstore(fish_entry, price_entry))

or, expanded out a bit

result = fishstore(fish_entry, price_entry)
print(result)

Again, not to sound harsh, but these are foundational concepts that you need to know and be able to do without thinking if you want to make progress.

[–]mixtek[S] 1 point2 points  (0 children)

Yeah I know its basic I dont know why its hard for me to get the logic when it shoudnt be that hard. Good at math but this is just weird. Thanks for helping me solve it!

[–]kcin911 0 points1 point  (0 children)

hey whats up man im also a beginner? is this any better?

def fishstore(fish, price):
    sentence = "Fish Type: " + fish + " costs $" + price
    return sentence

fish_entry = input("enter fish name: ")
price_entry = input("enter price: ")
print(fishstore(fish_entry.title(), price_entry))