0

I'm trying to print the solution of the following python function using command prompt but getting an error. I'm not sure whether the command which I am giving is wrong or there is any mistake in the code itself. Can you please check?

# A. donuts
# Given an int count of a number of donuts, return a string
# of the form 'Number of donuts: <count>', where <count> is the number
# passed in. However, if the count is 10 or more, then use the word 'many'
# instead of the actual count.
# So donuts(5) returns 'Number of donuts: 5'
# and donuts(23) returns 'Number of donuts: many'
def donuts(count):
  if count < 10:
    return 'Number of dounts:' + str(count)
  else:
    return 'Number of donuts: many'

I gave the following command in the command prompt

C:\>PythonCourse\google-python-exercises\basic\string1 donuts('10')

Getting the following error:

 File "C:\PythonCourse\google-python-exercises\basic\string1.py", line 77
    print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected))
SyntaxError: invalid syntax

I tried running the solution file as well but I get the same error. I'm new to python, any help would be appreciated. I'm using python 3.8. Please let me know if I should provide any other details.

AAM
  • 321
  • 5
  • 24
  • Hey I edited it. Please check. Not sure where is the syntax error – AAM Jul 09 '20 at 00:54
  • I'm looking at the error message an here the error comes in the `print` *statement*, which is a feature of Python 2. Is the course designed for Python 2 or 3? – NotAName Jul 09 '20 at 00:56
  • The course is designed for python 2.7 – AAM Jul 09 '20 at 00:57
  • Why are you using Python 3.8 then? Also note that Python 2.x is end-of-life'd; so I would find a more up-to-date course. – Selcuk Jul 09 '20 at 00:58
  • @Selcuk There is no duplicate question to this one. I'm using python 3 coz it's the latest. If – AAM Jul 09 '20 at 01:02
  • Note that the latest version of Python is **not** compatible with Python 2.x. The duplicate question explains one of such incompatibilities. You must use the exact same version as the course suggests, which is Python 2.7, or find another tutorial. – Selcuk Jul 09 '20 at 01:06

2 Answers2

2

Your solution seems to work for me, but it seems like the checker is expecting you to pass the count of donuts as a number in which case you should use a formatted string:

if count < 10:
    return f'Number of donuts: {count}'
else:
    return 'Number of donuts: many'

Also you have a typo in the word "donuts" in the second return statement.

NotAName
  • 3,821
  • 2
  • 29
  • 44
  • Nope. This does't work either. Same error Is there any mistake in the way I give the command in the command promopt. Also i would like to attach the file here, is there any option for that? – AAM Jul 09 '20 at 00:53
-1

You have to use bracket in print function in python3. Like this:

print ('Hello World')
fro
  • 402
  • 3
  • 8
  • Hey I tried this as well. Instead of return, I used the print format too. I got the same error. – AAM Jul 09 '20 at 00:55