Answer the question
In order to leave comments, you need to log in
What did I write wrong in the code?
import datetime
from datetime import datetime
FIO = input("Ваша Фамилия Имя и Отчество: \n")
print("Здравствуйте,",FIO)
AgePol = int(input("Введите свой возраст: \n"))
if AgePol < 0:
AgePol = AgePol * -1
else:
AgePol = AgePol
TY = datetime.now().year
AgePC = 1985
AgePC1 = TY - AgePC
Res = int(AgePC1 - AgePol)
Res_2 = int(Res * -1)
print("TY=",TY)
print("AgePC1=",AgePC1)
print("Res=",Res)
print("Res_2=",Res_2)
if Res>0:
if AgePol == 22 or AgePol == 23 or AgePol == 24 or AgePol == 25:
print('Вы старше меня на', Res, "лет.")
else:
if Res%10 == 0:
print("Мы ровесники)))")
elif Res%10 == 1:
print('Вы младше меня на', Res,"год.")
elif Res%10 >1<5:
print('Вы младше меня на', Res,"года")
elif Res%10 >=5<=20:
print('Вы младше меня на', Res,'лет.')
elif Res < 0:
if Res_2 == 0:
print("Вы страше меня на",Res_2,"год.")
elif 1 < Res_2%10 <= 4:
print("Вы старше меня на", Res_2, "года.")
elif 5 < Res_2%10 <= 20:
print("Вы старше меня на", Res_2, "лет.")
Answer the question
In order to leave comments, you need to log in
I would advise you not to try to figure it out, there is already some kind of mess, starting from multiplying by -1, ending with if blocks. Start over, name the variables so that it is clear what lies in them. It seems to me that you do not understand what Res is and what Res_2 is and why they are needed. The task is very simple, you need to subtract one number from another and that's it.
user_age = int(input('Введите свой возраст: '))
current_year = datetime.now().year
pc_age = current_year - 1985
if user_age > pc_age:
print('Вы старше на', user_age-pc_age, 'лет')
elif user_age == pc_age:
print('Мы ровесники')
else:
print('Вы младше на', pc_age-user_age, 'лет')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question