I have an Excel file and I want to extract some values from it whe it finds 7 or 14 or 13 in the following columns: remainingDaysE or remainingDaysG or remainingDaysI
I am having the following code in Python:
if remainingDaysE == 7 or remainingDaysG == 7 or \
remainingDaysE == 14 or remainingDaysG == 14 or \`enter code here`
remainingDaysE == 30 or remainingDaysG == 30:
# create an email with values extracted
One of the values that I need would be the value that gets me in the "If statement"
My question is: Is there any to get the value that got me into this is "if" statement? E.G: Was it remainingDaysE == 7 or was it remainingDaysG ==30 etc.. How do I get that specific value or is there any other way to reformat the code? I hope I made myself clear.
Thanks!
CodePudding user response:
Here is an example with the code you provided in your post. I hade to make up some variables as we don't have all the code:
remainingDaysE = 14
remainingDaysG = 43
def createemail(remainingDays):
print("pretending to create email with: " remainingDays "remaning Days")
def remainingdayfunction():
if remainingDaysE == 7 or remainingDaysE == 14 or remainingDaysE == 30:
return createemail(remainingDaysE)
if remainingDaysG == 7 or remainingDaysG == 14 or remainingDaysG == 30:
return createemail(remainingDaysG)
remainingdayfunction()
CodePudding user response:
The and
keyword is a logical operator, and
is used to combine conditional statements.
a = 200
b = 33
c = 500
if a > b and c > a:
print("Both conditions are True")
CodePudding user response:
If you only want to know the number of remaining days then you could do this:
remainingDaysE = 7
remainingDaysG = 99
remainingDaysI = 44
def create_email(remainingDays):
pass
for remainingDays in remainingDaysE, remainingDaysG, remainingDaysI:
if remainingDays in {7, 14, 30}:
create_email(remainingDays)
break