What am I doing wrong? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

What am I doing wrong?

I get either a 'cannot assign to literal' or 'cannot assign to operator' error in this string: int(cy) - int(UserAge) = 'B' Sorry if it is silly as a program but I'm just a 14 year-old learning to code. print('Welcome. This program will tell you which year you were born') UserAge=input('Please enter your age: ') print('Your age is') print (UserAge) while True: ansA = input('Do you confirm? ') y = 'Yes' n = 'No' if ansA == y: print('Thank You!') if ansA == n: UserAge=input('Please re-enter your age: ') else: UserAge=input('Please enter a valid answer: ') cy = input('What is the current year?') print('The current year is') print(cy) while True: ansCY = input('Do you confirm?') if ansCY == y: print('Thank you') if ansCY == n: cy = input('Please re-enter the current year') else: cy = input('Please enter a valid answer') int(cy) - int(UserAge) = 'B' print('You were born in') print(B) print('Thanks for using this test program!')

24th Oct 2020, 10:36 PM
Abderrahim Frini
Abderrahim Frini - avatar
2 Respuestas
+ 2
Change that line to B = int(cy) - int(UserAge) Always put the variable name to be assigned on the left of the =.
24th Oct 2020, 10:56 PM
Russ
Russ - avatar
+ 1
B should be an integer but you use it as a character .So instead you can declare B = .... Here in your code B= int(cy)-int(UserAge).
24th Oct 2020, 10:58 PM
HBhZ_C
HBhZ_C - avatar