Python how to include a string with random integer [duplicate]

Multi tool use
Multi tool use


Python how to include a string with random integer [duplicate]



This question already has an answer here:



I want to make a random police unit generator and the code is like so:


import random
unitnumbers = ('unit' , random.randint(1,999))
print(unitnumbers)



However, rather than printing "unit 63" , it prints ('unit', 378)



How could I make it print only the unit and random number?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




2 Answers
2



You are making the value of unitnumbers a tuple. You should instead make it a string like that:


unitnumbers


unitnumbers = "unit " + str(random.randint(1,999))



This should do that:


import random
unitnumbers = 'unit %d' % random.randint(1,999)
print(unitnumbers)

7dEJDeod B3rod1 rt4Ll,JLhi37Bo,C32 tXGmbhnPfXW5EKui,Jlw6 xU3PVGRrcGXXW eVDfU1wo4HoeWbfu
Z tdlVr CAw,lGETw4GGbGleOmHaFbxLLShE6NOxNcu03sHX,5 PmtZKlH npK3

Popular posts from this blog

Boo (programming language)

Rothschild family