Study Notes
- The judgment conditions for
if
not only include double equal signs, but also!=
,>
,<
,>=
,<=
. - Numbers with quotes are not equal to numbers. For example,
"178" != 178
. The number "178" with quotes is considered as text,string
type in the computer. The number 178 without quotes is considered as a number,number
type. - There are two types of number,
int
type andfloat
type.int
is an integer type without decimal parts.float
is a floating-point type that can have decimal parts. - In statements with multiple parentheses, you may encounter errors due to missing parentheses. Parentheses appear in pairs, if there is a left parenthesis, there must be a right parenthesis. The error in the tutorial is on the second line of the parentheses, because that line is not completed, it's not an error, but the next line reports an error because the previous line was not correctly completed.
- When errors occur while writing code and the issue is not apparent in the current line, check the previous line, as it may be due to the previous line not being correctly completed.
CODE
print("Generation Identifier")
varyear = int(input("Which year were you born? "))
if varyear < 2000 and varyear >= 1990:
print("You are a 90's kid")
elif varyear < 1990 and varyear >= 1980:
print("You are an 80's kid")
elif varyear < 1980 and varyear >= 1970:
print("You are a 70's kid")
else:
print("Are you an oldie or a young one?")