+ 1

Help me generate non-repeating numbers

Need help fixing my code so that it doesn't print the same number twice unless it's the last number generated, the one that goes from 1-20. https://code.sololearn.com/cOZ1fHl1gl70/?ref=app

21st Oct 2018, 7:48 PM
Alec Vindas
Alec Vindas - avatar
5 Antworten
+ 2
Why not generate a list between 1-n then randomly pick an element from it, print it then remove it or shuffle the list then iterate over it (not my idea). Shuffle idea: https://code.sololearn.com/cwiosjxUAE2d/?ref=app
21st Oct 2018, 7:53 PM
TurtleShell
TurtleShell - avatar
+ 2
Hi, here is a sample code you could use : https://code.sololearn.com/chMyZI4C8xW3/#py btw, you really dont need to use the import command 6 times in one code :) TurtleShell the shuffle is a great idea :)
21st Oct 2018, 8:08 PM
Proff
Proff - avatar
+ 2
You don't have to import a module each time you use it. Once is enough. The line 'for any in range(1)' doesn't do anything. It defines a variable 'any' that is set to 0 but isn't used anywhere. 'any' is a python keyword, so it shouldn't be used as a name for a variable https://code.sololearn.com/c1owuINvkAnE/?ref=app
21st Oct 2018, 8:13 PM
Anna
Anna - avatar
+ 2
Thanks for all the feed back!
22nd Oct 2018, 5:06 AM
Alec Vindas
Alec Vindas - avatar
0
Proff yeah, I wish I could say I came up with it
21st Oct 2018, 8:36 PM
TurtleShell
TurtleShell - avatar