Ask coding questions

← Back to all posts
How do I define my variables
Zakbets

So I try to define my variables like yearborn and currentyear and the call them later when I subtract the two but it will not call them

Answered by CodingElf66 [earned 5 cycles]
View Answer
Voters
Zakbets
Comments
hotnewtop
CodingElf66

The if statement has the wrong syntax. For Lines 28-30, do:

Zakbets

@CodingElf66 now it is saying monthsold is not defined

CodingElf66

@Zakbets I done it and it has no problem! If you don't mind, you can mark this comment as answered!

MrVoo

You should use f-strings instead of a bunch of variables and commas, like this:

Spacecraft

Your input is in the form of a string. In order for your equations to work, you need to convert your input from a string to an integer:

This will only work if your variables can be converted to integers. If the input was "three" for example, then it would fail when trying to convert to an integer.

Zakbets
Spacecraft

@Zakbets also, you are missing a closing ) on line 7.

Zakbets

@Spacecraft i do not see what my new problem is

Spacecraft

@Zakbets Seems to be working unless your birth month or day is lower than the current month or day. Using the absolute value here may help the problem:
monthsold = abs(monthborn - currentmonth)
daysold = abs(dayborn - currentday)

Spacecraft

@Zakbets On second thought, that may not work in all cases. If your birthday occurs between now and the end of the year, you'll have to come up with a formula to subtract one year from the age, and add the difference in months / days.

Zakbets

@Spacecraft I'am trying to make it call the current date by itself but i cant get it to call the right variable