-2

I'm taking a Python intro course and couldn't solve this problem.

Make this string correct and store it in a variable named 'q12'.

q12 = "4 % 2 = " + (4 % 2))

Any help would be much appreciated!

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Eve
  • 1
  • 1
  • Are you being asked to fix the line to allow it to execute? What type of variable is supposed to be stored in q12? – Ewan Brown Dec 27 '21 at 04:07
  • 1
    Is this what you are looking for: `q12 = "4 % 2 = " + str(4 % 2)` – j1-lee Dec 27 '21 at 04:08
  • You cannot ask us to do your homework for you. You need to make a good faith attempt to solve it yourself and then come to us if it doesn't work. – Tim Roberts Dec 27 '21 at 04:11
  • Welcome to Stack Overflow! Please take the [tour] and read [How to ask and answer homework questions](https://meta.stackoverflow.com/q/334822/4518341). What have you already tried? Do you at least know how to fix the syntax error? Do you know [how to convert a number to a string](/q/961632/4518341)? Or, even better, have you learned f-strings? If you want more tips, see [ask]. – wjandrea Dec 27 '21 at 04:12

1 Answers1

0

There are many ways, the simplest is to use the f-format, you put f before the string and curly braces around expresions:

>>> def q( m, n): return f"{m} % {n} = {m%n}"
...
>>> q( 53, 22)
'53 % 22 = 9'
baz
  • 1,317
  • 15
  • 10