gpt4 book ai didi

python - 编写一个简单的 Python 程序

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:20 25 4
gpt4 key购买 nike

我在为初级编程类(class)编写简单的 Python 程序时遇到了问题。如果有人可以查看我目前拥有的代码并指导我朝着正确的方向前进,将不胜感激!这是代码:

帮助满足护士到患者人员配置需求的计划

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()

最佳答案

将最后一段代码改为:

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()

由于 python 是基于缩进执行的。此外,从 printInfo 语句中删除 = 并使其成为:

nurses = getNurses(patients)
nurseAssistants = getAssistants(nurses)
printInfo(patients, nurses, nurseAssistants)

关于python - 编写一个简单的 Python 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11514216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com