[Python] Are there other ways to obtain a value from 2 ranges?

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning Python, and I would like to know if there are other functions, methods, or techniques to obtain a value from two ranges. I provide the only example I could came up with with my current knowledge. Any leads are quite appreciated:

    import random

    def choose_random_angle():
    range1 = list(range(1, 76))
    range2 = list(range(120, 231))
    combined_ranges = range1 + range2
    return random.choice(combined_ranges)


    I was expecting to be able to include both ranges, separated by ";" or something along the lines. However, after reviewing the documentation, range function can only contain start, end, and step. The solution I have works, but I am sure there is a more efficient way.

    Continue reading...

Compartilhe esta Página