-1

I am trying out some simple function building in Python, I use Jupyter Qt Console. This is my function:

def fishmarket(price):
    print("How much is the fish?")
    print("So you say the fish costs" % price "?")   
    if price > 5:
            print("That's too much!")
    else: print("That's fine by me")
    print("Have a nice day, sir!")

I would like people to call the function and define a price and then get an answer depending on the price. I get a syntax error around the question mark. How do I combine the string and the variable price in a single printout? I already learned from another answer that % should do the trick with numerical variables, but it didn't help.

DavidG
  • 24,279
  • 14
  • 89
  • 82
GaiusBaltar
  • 31
  • 1
  • 7
  • "% should do the trick" but not by just tossing it in there. What you are doing is called cargo cult programming, and it doesn't work. Please read through a tutorial (like the [official Python tutorial](https://docs.python.org/3.6/tutorial/index.html)). – TigerhawkT3 Apr 13 '17 at 10:09
  • As indentation is essential in Python, take care not to mess it when you paste your code here! – Thierry Lathuille Apr 13 '17 at 10:12

2 Answers2

-1

Do it with format:

print("You say the price is {}".format(price))

DavidG
  • 24,279
  • 14
  • 89
  • 82
Soloritur
  • 24
  • 10
  • As stated in [answer], please avoid answering unclear, broad, SW rec, typo, opinion-based, unreproducible, or duplicate questions. Write-my-code requests and low-effort homework questions are off-topic for [so] and more suited to professional coding/tutoring services. Good questions adhere to [ask], include a [mcve], have research effort, and have the potential to be useful to future visitors. Answering inappropriate questions harms the site by making it more difficult to navigate and encouraging further such questions, which can drive away other users who volunteer their time and expertise. – TigerhawkT3 Apr 13 '17 at 10:08
-1

You can try this

def fishmarket(price):
  print("How much is the fish?")
  print("So you say the fish costs", price, "?")
    if price > 5:
  print("That's too much!")
  else: print("That's fine by me")
  print("Have a nice day, sir!")

or that

def fishmarket(price):
      print("How much is the fish?")
      print("So you say the fish costs {} ?".format(price))
        if price > 5:
      print("That's too much!")
      else: print("That's fine by me")
      print("Have a nice day, sir!")
jeremie
  • 971
  • 9
  • 19
  • As stated in [answer], please avoid answering unclear, broad, SW rec, typo, opinion-based, unreproducible, or duplicate questions. Write-my-code requests and low-effort homework questions are off-topic for [so] and more suited to professional coding/tutoring services. Good questions adhere to [ask], include a [mcve], have research effort, and have the potential to be useful to future visitors. Answering inappropriate questions harms the site by making it more difficult to navigate and encouraging further such questions, which can drive away other users who volunteer their time and expertise. – TigerhawkT3 Apr 13 '17 at 10:08