Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating a random number in a string

I’m trying to create a variable that is a string that includes a random number, but it keeps telling me that my syntax is invalid, highlighting the r in rand.

import random as rand
Smoke = str(rand.randint(20, 40)" Smoke Shells")

What mistake have I made here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are a few things wrong in the code, like you shouldn’t convert a string to a string

str(" Smoke Shells")

and you can’t add a string to an int.
This should work, though:

import random as rand
Smoke = str(rand.randint(20, 40)) + " Smoke Shells"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading