Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing a simple Python program

Tags:

python

I'm having trouble writing a simple Python program for a beginner programming class. If someone could look at the code I currently have and guide me in the right direction it would be much appreciated! Here is the code:

A program that helps fulfil nurse to patient staffing needs

def main():
    print 'Welcome to the PACU nurse to patient program'
    print
    patients = inputPatients()
    nurses = getNurses(patients)
    nurseAssistants = getAssistants(nurses)
    printInfo = (patients, nurses, nurseAssistants)
   
    raw_input()

def inputPatients():
    patients = input('Enter the number of patients for this shift (up to 40): ')
    return patients

def getNurses(patients):
    nurses = (1.0 / 3.0) * patients
    return nurses

def getAssistants(nurses):
    nurseAssistants = (1.0 / 2.0) * nurses
    return nurseAssistants

def printInfo(patients, nurses, nurseAssistants):
    print 'The number of patients for this shift is:', patients
    print 'The number of nurses needed is:', nurses
    print 'The number of nurses Assistants is:', nurseAssistants


main()
like image 238
Michael Hanson Avatar asked Jan 27 '26 08:01

Michael Hanson


2 Answers

Change the last segment of code to:

def printInfo(patients, nurses, nurseAssistants):
    print 'The number of patients for this shift is:', patients
    print 'The number of nurses needed is:', nurses
    print 'The number of nurses Assistants is:', nurseAssistants

main()

Since python executes based on indentation. Also, remove the = from the printInfo statement and make it:

nurses = getNurses(patients)
nurseAssistants = getAssistants(nurses)
printInfo(patients, nurses, nurseAssistants)
like image 151
hjpotter92 Avatar answered Jan 29 '26 21:01

hjpotter92


Previous answers have hinted at the main problem but not explained why you are not seeing any output.

The following assigns a tuple containing the 3 values for patients, nurses, and nurse assistants to the variable named printInfo.

printInfo = (patients, nurses, nurseAssistants)

It does not produce any output and it does not call the function printInfo() as you are probably expecting. What you actually need is to make a function call:

printInfo(patients, nurses, nurseAssistants)
like image 26
mhawke Avatar answered Jan 29 '26 21:01

mhawke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!