2017-04-19 7 views
0

私はPythonにはかなり新しく、1週間この割り当てに取り組んでおり、正しく実行することはできません。私は今、私がそれを定義したにもかかわらず、関数get_in_codeが定義されていないことを私に伝えるエラーを取得しています。どんな助けでも大歓迎です!定義されているにもかかわらず、関数が定義されていません...不完全な実行

SENTINEL = 'XXX' 
DAY_CHARGE = 1500.00 
#Define get_days 
     def get_days(): 
      good_data = False 
      while not good_data: 
       try: 
        n_days = int(input("Please enter the number of days you stayed: ")) 
       except ValueError: 
        print("Error, Bad Data") 
       else: 
        if n_days > 0: 
        good_data = True 
       else: 
        print("This is bad data, please re enter data") 
      return n_days 

     #define get_cost(p) 
     def get_cost(): 
      cost = float(input("Please enter the cost for the procedures: ")) 
       while cost < 0: 
        print("Procedure cost cant be negative: ") 
        cost = float(input("Please enter the cost for the procedures: ")) 
       return cost 

     #define med cost 
     def med_cost(): 
      med_cost = float(input("Enter the cost of your medicine: ")) 
       while med_cost < 0: 
        print("Medicine cost cant be negative: ") 
        med_cost = float(input("Enter the cost of your medicine: ")) 
       return med_cost 
     #Find day cost 
     def find_day_cost(in_code, n_days): 
      day_cost = n_days * DAY_CHARGE 
      if in_code == 'ZH': 
       p_day_cost = day_cost * 0.20 
       in_day_cost = day_cost *0.80 
      elif in_code == 'HH': 
       p_day_cost = day_cost * 0.10 
       in_day_cost = day_cost * 0.90 
      elif in_code == 'CH': 
       p_day_cost = day_cost * 0.25 
       in_day_cost = day_cost * 0.75 
      else: 
       p_day_cost = day_cost 
       in_day_cost = 0 
       return p_day_cost, in_day_cost 

     #find procedure cost 
     def find_proc_cost(in_code, cost): 
      if in_code == 'ZH': 
       p_proc_cost = 0 
       in_proc_cost = cost 
      elif in_code == 'HH': 
       p_proc_cost = cost * 0.10 
       in_proc_cost = cost * 0.90 
      elif in_code == 'CH': 
       p_proc_cost = cost * 0.50 
       in_proc_cost = cost * 0.50 
      else: 
       p_proc_cost = cost 
       in_proc_cost = 0 
      return p_proc_cost, in_proc_cost 

     #find medicine cost 
     def find_med_cost(in_code, med_cost): 
      if in_code == 'ZH': 
       p_med_cost = 0 
       in_med_cost = med_cost 
      elif in_code == 'HH': 
       p_med_cost = med_cost * 0.10 
       in_med_cost = med_cost * 0.90 
      elif in_code == 'CH': 
       p_med_cost = med_cost * 0.50 
       in_med_cost = med_cost * 0.50 
      else: 
       p_med_cost = med_cost 
       in_med_cost = 0 
       return p_med_cost, in_med_cost 

     #Display pat_info 
     def display_pat_info(pat_name, in_name): 
      print("City Hospital - Patient Invoice") 
      print("Patient Name: ", pat_name) 
      print("Insurance: ", in_name) 

     #display day cost 
     def display_day_cost(p_day_cost, in_day_cost): 
      print("Patient Day Cost: ", p_day_cost,"\tInsurance Day Cost: ", in_day_cost) 

     #display procedure cost 
     def display_proc_cost(p_proc_cost, in_proc_cost): 
      print("Patient Procedure Cost: ", p_proc_cost, "\tInsurance Procedure Cost: ", in_proc_cost) 

     #display medicine cost 
     def display_med_cost(p_med_cost, in_med_cost): 
      print("Patient Medicine Cost: ", p_med_cost, "\tInsurce Medicine Cost: ", in_med_cost) 

     #Display totals 
     def display_totals(total_pat, total_in): 
      print("Total Billed To Patient: ", total_pat, "\tTotal Billed To Insurance: ", total_in, "\tTotal Bill: ", (total_pat + total_in)) 

     #display day_totals 
     def display_day_totals(total_zip, total_happy, total_cheap, total_pat): 
      print("City Hospital - End Of Day Billing Report") 
      print("Total Dollar Amount Billed Today: ",  total_zip+total_happy+total_cheap+total_pat) 
      print("Total Billed To Zippy Healthcare: ", total_zip) 
      print("Total Billed To Happy Healthcare: ", total_happy) 
      print("Total Billed To Cheap Healthcare: ", total_cheap) 
      print("Total Billed To Uninsured: ", total_pat) 

      #display day_counts() 
      def display_day_counts(zip_count, happy_count, cheap_count, no_in_count): 
      print("The total amount of Zippy Healthcare patients is: ", zip_count) 
      print("The total amount of Happy Healthcare patients is: ", happy_count) 
      print("The total amount of Cheap Healthcare patients is: ", cheap_count) 
      print("The total amount of Uninsured patients is: ", no_in_count) 
#def main 
def main(): 

    #Counters and accumulators 
    total_zip= 0.00 
    total_cheap= 0.00 
    total_happy= 0.00 
    total_pat= 0.00 
    zip_count= 0 
    cheap_count= 0 
    happy_count= 0 
    no_in_count= 0 
    total_in = 0 

    #Open file 
    try: 
     Pat_File = open('PatientBill.txt', 'w') 
    except ValueError: 
     print("*****ERROR***** - Corrupt File") 
    else: 
     file_exist = True 

    #Priming read 
    pat_name = input("Please enter the patients name: (XXX to stop program)") 

    #Processing loop 
    while pat_name != SENTINEL: 
     #Input data 
     in_code = get_in_code() 
     num_days = get_days() 
     proc_cost = get_cost() 
     med_cost = med_cost() 

     #find each cost 
     pat_day, insure_day = find_day_cost(in_code, num_days) 
     pat_proc, insure_proc = find_proc_cost(in_code, proc_cost) 
     pat_med, insure_med = find_med_cost(in_code, med_cost) 

     #update accumulators and totals 
     total_pat += pat_day + pat_proc + pat_med 
     if in_code == 'ZH': 
      zip_count += 1 
      total_zip += in_day_cost + in_proc_cost + in_med_cost 
      in_name = 'Zippy Healthcare' 
     elif in_code == 'HH': 
      happy_count += 1 
      total_happy += in_day_cost + in_proc_cost + in_med_cost 
      in_name = 'Happy Healthcare' 
     elif in_code == 'CH': 
      cheap_count += 1 
      total_cheap += in_day_cost + in_proc_cost + in_med_cost 
      in_name = 'Cheap Healthcare' 
     else: 
      no_in_count += 1 
      in_name = 'Uninsured' 
      total_in = total_zip + total_happy + total_cheap 
     #displays patients invoice 
     display_pat_info(pat_name,in_name) 
     display_day_cost(pat_day, insure_day) 
     display_proc_cost(pat_proc, insure_proc) 
     display_med_cost(pat_med, insure_med) 
     display_totals(pat_day + pat_proc + pat_med, insure_day + insure_proc + insure_med) 

     #Write output to file 
     if file_exist: 
      Pat_File.write(pat_name, pat_day+pat_med+pat_proc) 

     #Get next patients name 
     pat_name = input("Please enter the patients name: (XXX to stop program)") 
     #Close the output file 
     if file_exist: 
      Pat_File.close() 

     #display the accumlators and totals 
     display_day_totals(total_zip, total_happy, total_cheap, total_pat) 
     display_day_counts(zip_count,happy_count,cheap_count,no_in_count) 
     #define get_in_code 
     def get_in_code(): 
      in_code = input("Please enter one of the insurance codes, ZH, CH, HH, XX") 
     while in_code not in ('ZH', 'HH', 'CH', 'XX'): 
      print("***Please enter a proper insurance code***") 
      in_code = input("Please enter one of the insurance codes, ZH, CH, HH, XX") 
     return in_code 

main() 
+0

こんにちは。まずインデントを修正してください。あなたのコードがここに正しく書かれていれば、 'def main'の後にあるすべてのコードが関数の中にないことを意味します。 – valeas

+0

コード例を最小限に抑えようとすると、その効果がまだ分かりませんが、原因を突き止めるのに役立ち、重要でないものをスクロールすることによって誰も退屈しないという副作用があります。 – guidot

+0

深呼吸してください。時には、あなたがプロジェクトで膝が深いときは、もう何も働かないようです。しかし、あなたが一歩前進して、あなたがやっていることを本当に評価すると、再び明確になるでしょう。 :) –

答えて

0

Pythonはインタープリタ言語です。関数を使用する前に関数を定義する必要があります。関数定義をファイルの先頭に移動するだけです。

問題はインデントもあります。 return文の直後に、whileの中にメソッドを定義しています。実際の機能はまったく定義されていません - 通訳者はこれらの行に到達しません。

さらに、コードは「汚い」です。コードを別のクラス/モジュールに分割します。責任を明確に定義した領域を作成すると、コードが改善され、作業が容易になります。

+0

私はそれが後に書かれている他の割り当てを完了したようにどこに関数が書かれているかはまったく問題ではないと思った。私はそれを変更し、実行を終了しましたが、私は0.00として定義されている変数total_patは定義されていません...それはちょうどhahaを終了しないようです –

+0

あなたはインデントに注意する必要があります。問題のコードを適切に書式化してください。 –

+0

私はそれがちょうどそれをそれを投げ捨てて、それを上に置き換えて、それが崇高な上で正しくインデントされている、残念これは私の最初の投稿です。クイックフォーマットのための助け、これは4スペース技法を使用していました –

関連する問題