I am learning Python and working on a sequencing program
In the program I have an attribut called 'Uptime'
Uptime has a fixed value of 60mins (for each day)
I want to create a function that will conditionnally Update the 'Uptime'
To drive more clarity, I use an excel to retrieve the Uptime value:
Uptime_data = pd.read_excel(excel_file, sheet_name='Up_value')
And here is the function I tried to create in order to not use a fixed value, but rather a value that will change accordingly to another attribut called 'Day':
def get_uptime_value(Uptime_data, day : Day, week : Week):
if day[Week] == 7:
Uptime_data += 120
return Uptime_data
The function itself has no error, but nothing changes in the Program.
Can you please help and spot what am I doing wrong?
Many thanks !
I have a DataFrame where I have all the info to calculate the Italian Fiscal Code for individuals but I am facing the following problem.
I am trying to use the function below to calculate the Fiscal Code but in case of error (for example it is not able to calculate the fiscal code because of a country doesn't exist anymore), the function always write, for each line, what is in the except instead of writing the fiscal code where all the info are available and correct and what is in the except only in case a error is find.
Could you help me to find a solution?
Thanks
def check(df_PF):
try:
a=[codicefiscale.encode(surname=df_PF['cognome'][i],
name=df_PF['nome'][i],
birthdate=(df_PF['data_nascita'][i]),
sex=df_PF['tipo_sesso'][i],
birthplace=df_PF['den_comune_nascita'][i])
if (pd.notna(df_PF['cognome'][i])) &
(pd.notna(df_PF['nome'][i])) &
(pd.notna(df_PF['data_nascita'][i])) &
(pd.notna(df_PF['tipo_sesso'][i])) &
(pd.notna(df_PF['den_comune_nascita'][i]))
else None for i in range(0,len(df_PF))]
return(a)
except:
pass
return ('Not Available')
Basically, the goal of this program is to take input from the user on what they want to order, process the cost of the item and tack on sales tax and a tip and return that. I'm struggling with how to go about getting my program to take input and run an if elif else statement based on what the input is.
I'm fairly new and I'm still figuring out how to ask a constructive question, so bear with me here. Also, I know there a bits of it that are unfinished, which may factor into it, but I'm not really concerned with the incomplete bits
I've tried making the if statement conditions dependent on the input given using the == operator as well as changing that to an "if answer is __: print a response. I'm fairly confident that I can get the program to print out a tip and tax tacked onto a price, but everything I've tried so far keeps exiting my program after receiving any form of input.
salesTax = 0.07 #the tax added onto the total
tip= 0.18 #the percentage for a tip
steak= 96 # a var for a steak priced so deliciously, that it *must* be good.
goose= 42 #var for the oddly familiar, yet disturbingly alien meal that is goose.
narwhal= 109 #var for a meal that questions its own existence, then laughs in the face of that question
menu = ['high-stakes steak', 'uncanny boiled goose', 'endangered carribrean narwhal caccitore']
print("Tonight's menu at Joe's ethically questionable eatery includes")
print(menu)
input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
answer = input
if answer == 'goose':
print("Ah, very good monsieur the cost will be 42. We will beegen ze cooking of ze goose")
elif answer is 'steak':
print("Ah, a high roller, we will begin")
I expect it to take 'goose' as an answer and print a response (eventually i'd make this take the number assigned to goose and calculate tax), but it simply ignores any input every single time.
input is a build-in function, you should assign the value got from input, but your codes assign the function itself to your variable answer
answer = input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
You need to assign your input to a variable. Your input is just reading from the keyboard and you don't save that value. Fix this with:
answer = input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
if answer == 'goose':
I have a text file:
E5341,21/09/2015,C102,440,E,0
E5342,21/09/2015,C103,290,A,290
E5343,21/09/2015,C104,730,N,0
E5344,22/09/2015,C105,180,A,180
E5345,22/09/2015,C106,815,A,400
E5346,23/09/2015,C107,970,N,0
E5347,23/09/2015,C108,1050,E,0
E5348,23/09/2015,C109,370,A,200
E5349,25/09/2015,C110,480,A,250
E5350,25/09/2015,C111,330,A,330
E5351,25/09/2015,C112,1750,E,0
E5352,28/09/2015,C113,1500,N,0
E5353,28/09/2015,C114,272,A,200
E5354,29/09/2015,C115,560,E,0
E5355,29/09/2015,C116,530,A,450
E5356,29/09/2015,C117,860,E,0
E5357,29/09/2015,C118,650,E,0
E5358,29/09/2015,C119,380,A,380
E5359,29/09/2015,C120,980,N,0
E5360,30/09/2015,C121,1375,E,0
E5361,01/10/2015,C122,374,A,374
The E stands for the estimate number
The date following the estimate number is the estimated date
The C stands for the customer number
The number following the customer number is the final total in £
The letter after the final total tells you if the job was accepted(A) or not accepted (N) or the job was just an estimate (E)
The number after the status^ is the total amount already paid in £
I want to find out how if I enter one of the estimate numbers in python can I print out the date or work out the outstanding payments and find out what status the job is.
I've tried to research this but I don't understand it, I would really appreciate any help towards this.
The expected outcome if i put in the estimate number of 5353 is meant to show the date which would be 28/09/2015 for that example
The basic idea in Python 2 (note I have not tested this, but it should be close or work as is):
search = '5356' # supply this as your search
search = 'E'+search
fh = open('textfile.txt')
for line in fh:
elements = line.split(',')
if len(elements) == 6:
if elements[0] == search:
print 'For Estimate #'+search
print 'date:'+elements[1]
print 'cust:'+elements[2]
print 'totl:'+elements[3]
print 'stat:'+elements[4]
print 'paid:'+elements[5]
fh.close()
Now... go look up each statement in that example in the Python 2 documentation and see what the various items in it do. That'll give you a little kickstart towards learning the language, if you are ever going to do any more in it.
Keep in mind that failure is possible: What if the text file name is wrong, for instance, and the file open fails? You'll want to look at the try and except Python language elements.
Everyone needs to start somewhere, which is why I didn't give you a snarky "show your work" answer. So here's your start. Go forth and learn. :)
Sorry that this is a bit of an amateur question, but i can't see what i'm doing wrong here, and it always helps if you get someone else to look at your code!
So i want people to be sorted into a different house depending on their birth month, and my string is being sliced at the right point (confirmed with a quick test in the interactive prompt) but house is always set to the else statement - which shouldn't happen...
Any help will be much appreciated!
(please ignore the append_to_file function also - just focusing on the get_user_inputs function)
(Text wouldn't format properly so i had to link to pastebin:)
CODE IS HERE https://pastebin.com/DzkeZ8bq
had to put code for a pastebin link so have a print statement
print("You're awesome if you help me!")
FURTHER EXPLAINATION:
So say if the following test data is used:
firstName = "Joe"
lastName = "Bloggs"
dateOfBirth = "10/05/2002"
It should sort Joe Bloggs into Saturn house (as dateOfBirth[3:5] is '05', meaning that '05' is in the list 'sat')
But instead, Joe Bloggs is sorted into Mars house (because the else statement has no condition, so my code seems to be defaulting to that.)
Again, thanks in advance :)
try changing
if dateOfBirth[3:5] in nep == True:
To
if dateOfBirth[3:5] in nep: