Hi, guys. Im working on a program for a class. Its an inpatient or outpatient hospital charges program. here is what ive gotten so far.
Any other critiques of my overall code will be absolutely welcomed. Thanks.
def inPatientFunction(hospitalDailyRate,numOfDaysInHospital,medicationCharges,hospitalServicesCharge): totalPatientCharges=hospitalDailyRate*numOfDaysInHospital*(medicationCharges+hospitalServicesCharge) return totalPatientCharges #creating function for an outpatient def outPatientFunction(medicationCharges,hospitalServicesCharge): totalPatientCharges=medicationCharges+hospitalServicesCharge return totalPatientCharges #creating function to run a loop for type of patient charges def checkPatientType(): if (patientType==0): while True: try: hospitalServicesCharge=float(input('Please enter the hospital service charges for your care $ ')) medicationCharges=float(input('Please enter the charges for the hospital medication $ ')) if (hospitalServicesCharge>=0 and medicationCharges>=0): break except ValueError: print('Invalid entry, try again') else: while True: try: hospitalDailyRate=float(input ('Please enter the daily charge for the hospital stay $ ')) numOfDaysInHospital=int(input ('How many days in total was the hopsital stay? ')) hospitalServicesCharge=float(input ('Please enter the hospital service charges for your care $ ')) medicationCharges=float(input ('Please enter the charges for the hospital medication $ ')) if (hospitalServicesCharge>=0 and medicationCharges>=0 and hospitalDailyRate>=0 and numOfDaysInHospital>=0): break except ValueError: print('Invalid entry, try again') #creating conditional statement to call correct function if (patientType): return inPatientFunction(hospitalDailyRate,numOfDaysInHospital,medicationCharges,hospitalServicesCharge) else: return outPatientFunction(medicationCharges,hospitalServicesCharge) #establishing variables at zero patientType=0 totalPatientCharges=0 #asking user for type of patient typeOfPatient=input('Is this an inpatient or outpatient? ') if (typeOfPatient=='inpatient'): patientType=1 #assigning a value to the total patient charges variable depending on what function has been used totalPatientCharges= checkPatientType() #showing user the total amount for hospital charges print ('Total hospital charges are $ ', format(totalPatientCharges,'.2f'))Towards the end when I ask the user if theyre an inpatient or outpatient, instead of doing a string comparison which is prone to user typos, is there a more fool proof way to ask the user this question? like press 1 for inpatient or press 0 for outpatient and reject all other inputs? and if I do change it to that style of input, what part of my code will I have to change? Because it runs good right now,I just want to get rid of that possible typo factor
Any other critiques of my overall code will be absolutely welcomed. Thanks.