[Tutor] SYNTAX ERROR MESSAGE

Alex Kleider alexkleider at gmail.com
Fri Jul 23 18:56:48 EDT 2021


On Fri, Jul 23, 2021 at 2:01 PM Chukwuemeka Ohakwe via Tutor <
tutor at python.org> 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
>

It seems you are not posting in text mode (a common problem, one of which
I've been guilty myself in the past) so your code is all mushed together
and is no longer Python.
I've tried to unravel it and get the following:
from  random import randint

def pick(words):
    num_words = len(words)
    num_picked = randint(0, num_words - 1)
    word_picked = words[num_picked]
    return word_picked

print(pick(name), pick(verb), 'a', pick(noun), end='.\n')

The error I get is:
Traceback (most recent call last):
  File "tutor.py", line 9, in <module>
    print(pick(name), pick(verb), 'a', pick(noun), end='.\n')
NameError: name 'name' is not defined

Also: 'verb' and ''noun" are not defined.
If you define them as follows:

name = "Chuck"
verb = "code"
noun = "Python"

..then the code executes although it's not clear to me what you are
trying to achieve.


_______________________________________________

> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list