+ 1

¿Why Can't I import random? [FIXED]

It shows: SyntaxError: invalid character in ...

21st Feb 2022, 9:04 AM
‎‏‪Óscar Gutiérrez‬‏‎
‎‏‪Óscar Gutiérrez‬‏‎ - avatar
19 Answers
+ 7
It's fixed. I had to rewrite the import random sentence because I copy-pasted it. Thanks!
21st Feb 2022, 9:24 AM
‎‏‪Óscar Gutiérrez‬‏‎
‎‏‪Óscar Gutiérrez‬‏‎ - avatar
+ 6
You probably have an invisible character somewhere appearing as whitespace. This is very common if you copied and pasted to the playground. Try deleting and re-adding the whitespaces manually.
21st Feb 2022, 9:18 AM
ChaoticDawg
ChaoticDawg - avatar
+ 5
please show us your code, we can import random in sololearn: https://code.sololearn.com/cD27z054XNcg
21st Feb 2022, 9:10 AM
NEZ
NEZ - avatar
+ 5
ChaoticDawg it's happening to me too a lot of times when i copy paste the code from the browser. For small bits of code, your solution is reliable. But when the code is like a 100 line long, what to do? Is there any way to do this copy paste without the special characters insertion?
21st Feb 2022, 9:27 AM
Rishi
Rishi - avatar
+ 4
I don't know of a way to copy without the invalid characters (unless copying from an IDE like the ones from Jetbrains), but ya a program could definitely be written to remove those invalid characters. Of course, it would need to be ran somewhere other than SL (mobile), because you can't copy from the output of the playground, at least on my device(s).
21st Feb 2022, 9:37 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
‎‏‪Óscar Gutiérrez‬‏‎ yeah true🙌 but just in case there's a way to copy them without those characters...
21st Feb 2022, 9:32 AM
Rishi
Rishi - avatar
+ 3
ChaoticDawg unless it is ran in a Sololearn web code😁
21st Feb 2022, 9:43 AM
Rishi
Rishi - avatar
+ 3
Rishi Yes, this is true. The old version of the web SL playground used to highlight where these invalid characters were (would see red dots or something where there should be a space etc). I don't think the current version does this anymore, but you could try it. 😉
21st Feb 2022, 9:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
ANONYMOUS ohh okay that's already a function😅👍
22nd Feb 2022, 12:09 PM
Rishi
Rishi - avatar
+ 3
Shankar no you can't use pygame module on Sololearn as far as i know, you've to go with some other interpreter application
22nd Feb 2022, 4:11 PM
Rishi
Rishi - avatar
+ 2
It would be great a code to remove special insertion characters.
21st Feb 2022, 9:30 AM
‎‏‪Óscar Gutiérrez‬‏‎
‎‏‪Óscar Gutiérrez‬‏‎ - avatar
+ 2
‎‏‪Óscar Gutiérrez‬‏‎ i don't know, i was asking that to ChaoticDawg
21st Feb 2022, 9:36 AM
Rishi
Rishi - avatar
+ 2
Shankar which module do you want to install?
22nd Feb 2022, 12:09 PM
Rishi
Rishi - avatar
+ 1
Rishi Tell me...
21st Feb 2022, 9:34 AM
‎‏‪Óscar Gutiérrez‬‏‎
‎‏‪Óscar Gutiérrez‬‏‎ - avatar
+ 1
how can we install python modules in solo learn
22nd Feb 2022, 11:07 AM
Shankar
+ 1
Rishi I want to install pygame module
22nd Feb 2022, 2:42 PM
Shankar
+ 1
Okkk Thanks
22nd Feb 2022, 4:27 PM
Shankar
0
Its because you haven't added python to path, install python again in your system with the help of YouTube and use pycharm community edition....
21st Feb 2022, 4:01 PM
Saad Khan
Saad Khan - avatar