[Python] Convert an input result/string to integer in Python

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am having issue with running this code. When I try to run it, it says it won't work because age is a string. How do I convert the string to an integer? I have also tried to do 18 - int(age) and that won't work either.

    age = input ("How old are you? (): ")
    if int(age) > 18 :
    print("You're old enough to drink")
    else:
    print("You're not old enough to drink. Wait", + 18 - age, "more years")

    Continue reading...

Compartilhe esta Página