[Tutor] SYNTAX ERROR MESSAGE

dn PyTutor at DancesWithMice.info
Fri Jul 23 19:15:05 EDT 2021


On 23/07/2021 15.19, Chukwuemeka Ohakwe via Tutor wrote:
> From  random import randintdef pick(words):    num_words = len(words)    num_picked = randint(0, num_words - 1)    word_picked = words[num_picked]    return word_pickedprint(pick(name), pick(verb), 'a', pick(noun), end='.\n')
> 
> Good day friends!please why does this program send error message when I run it?
> The error is highlighted at r in random. It reads: Syntax Error                                                                             Invalid Syntax 

>>> From  random import randint
  File "<stdin>", line 1
    From  random import randint
          ^
SyntaxError: invalid syntax


>>> from  random import randint


Yes, it can be confusing when Python notices the error at one point (the
'arrow'/highlight), but the actual fault was caused earlier in the code.
The trick is to look a short distance 'backwards'!
-- 
Regards,
=dn


More information about the Tutor mailing list