Jump to content

Python Variable Subtracting and If/Else statements

itchkowb
Go to solution Solved by reniat,

instead of = < do <= for less than or equal to

 

Also, make sure to indent the lines in the if and else statement since python uses indentation to structure logic:

if current_year - int(patron_year) <= alchohol_consumtion_age:
	print("Tsk, Tsk, no alcohol for you")
else: 
	print("It's Beer O'Clock, my dude or dudette") 

 

I'm new to python, so I wanted to do a easy project to get some practice. I decided on a calculator that determines if you're of the age to drink alcohol. I'm in the US, so it's 21. I have the user input part working, but when it comes to the calculating part, I'm having some trouble. If anyone knows how to help or has some good resources, I'd be very appreciative. Here's my code:

current_year = 2019
alchohol_consumtion_age = 21
print("--------------------------------------")
print("~~~~~~DRINKING AGE CALCULATOR~~~~~~~")
print("--------------------------------------")
patron_year = input("What Year Were You Born In, My Friend? ")
print("Ok, so you were born in " + patron_year) 
patron_day = input('And what day might you have joined us on earth? ')
print("Ahhhh, the " + patron_day)
print("I had a cousin, who was born on the very same day! What a small world it is")
print("what a small world, indeed")
if current_year - int(patron_year) = < alchohol_consumtion_age:
print("Tsk, Tsk, no alcohol for you")
else: 
print("It's Beer O'Clock, my dude or dudette") 
print("Drink Responsibly")
print("-------------------------------------")

Also, whenever I run it, I get this error: 

Quote

 File "/home/brett/python test.py", line 12
    if current_year - int(patron_year) = < alchohol_consumtion_age:
                                       ^
SyntaxError: invalid syntax
Terminated

 

Thanks

 

(also if i left out any info im sorry, i didn't know what to and what not to post)

Link to comment
Share on other sites

Link to post
Share on other sites

instead of = < do <= for less than or equal to

 

Also, make sure to indent the lines in the if and else statement since python uses indentation to structure logic:

if current_year - int(patron_year) <= alchohol_consumtion_age:
	print("Tsk, Tsk, no alcohol for you")
else: 
	print("It's Beer O'Clock, my dude or dudette") 

 

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×