[Python] Is there an alternative for case by case "if" statements for comparing an input...

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

  1. Stack

    Stack Membro Participativo

    First semester python student here, so this is probably a very basic and stupid question.

    I have 4 sets of ranges:

    age=int(input("Enter your age: "))
    range1=range(0,12)
    range2=range(13,19)
    range3=range(20,64)
    range4=range(65,100)


    I want it to display the corresponding range of the input integer without using 4 sets of if age in rangeX statements, is there any way to do this?

    Continue reading...

Compartilhe esta Página