[Python] Printing a random amount of characters a random amount of times using only one line...

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    I only have one line to work with. I have string "fo0" and want to print each character a random amount of times and redo that entire statement another random amount of times, resulting in something like:

    ffooooo000 ffffffoo00 fffo00000000


    How do I go about this, using for loops or something similar? As far as I've gotten:

    import random; x = "fo0"; print "".join(x for i in range(0,random.randrange(0,40)))


    All this results in is "fo0fo0fo0fo0fo0fo0".

    Continue reading...

Compartilhe esta Página