Python 'Invalid Syntax"

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python

Hi,

I am trying to make some code to work, however, whenever I run it, it says “Invalid Syntax”
This is the code (I had copied this from our teacher so I’m pretty sure it should work)

import random
random.seed()
Numlist =
while len(Numlist) <6:
While True:
Num = Random.choice
If Num in Numlist:
Null
else:
Numlist.append(Num)
break
Print(Numlist)

The “invalid syntax” is in line five…

Thanks,

<do not remove the three backticks above>

This code is invalid in so many ways. And it should not work, definitely.

While, If, Random and Print should be lowercase.

else and if should have the same indentation level.

To random.choice you should pass a sequence.

Null? Does not make any sense.

I would guess that this code should be written like this:

import random

random.seed()
num_list = []
x = range(100)

while len(num_list) < 6:
  num = random.choice(x)
  if num not in num_list:
    num_list.append(num)

print(num_list)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.