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,
This code is invalid in so many ways. And it should not work, definitely.
if should have the same indentation level.
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)
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.