[Python] Trying to make an age calculator, but I have some problems when trying to make error...

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

  1. Stack

    Stack Membro Participativo

    I think the title says it all but I'll give you the code.

    stop=0
    while stop != 'q':
    print("Age calculator")
    name = input("Name: ")
    print("Type in your age")
    age = input("Age: ")

    months = age * 12
    days = age * 365
    weeks = age * 52
    hours = days * 24
    minutes = age * 525948
    seconds = age * 31556926

    if type(age) == int:
    print (name, "lives for", months, "months", weeks, "weeks", days, "days", hours, "hours", minutes, "minutes and", seconds, "seconds")

    else:
    print("Please type in a number")


    print()
    print("Try again? Press ENTER")
    print("Quit? Press 'q' and then ENTER")
    print()
    stop = input()


    So the thing is that I want it to give you the months, weeks, days etc. Now I know how to do this but now I'm trying to make a line that would say: Please type in a number. If the user would type in characters instead of numbers. When I run this code above every time I type in a number it gives me the line "Please type in a number" and when I type in a character it does the same.

    What am I doing wrong here?

    Continue reading...

Compartilhe esta Página