Search code examples
pythonlistpython-2.7programmers-notepad

Years display in Python from a age and print every year since birth


I want to create a code in Python that asks the user for their age and displays on the screen every year since birth, separated by commas. Using for.

Like this example:

How old are you?: 37 1985, 1986, 1987, 1988, ... 2017, 2018, 2019, 2020, 2021, 2022

Please help me.

Thank you :)


Solution

  • You try maybe below code

    age = input("How old are you? \n")
    year = 2022-int(age)
    
    for x in range(year, 2023):
      print("{},".format(x))