2017-03-10 5 views
1

質問

私はPythonを使い始めました。私は最初に取り組んでいるこの基本的なプログラムをループバックしようとしています。Python内でコマンドを返す

現在のプロセスは終了プログラムを中断し、私は何が欠けているのか分かりません。どのように私はこの作品を作るためにリターン/セレクトを再度方向づけることができますか?

PROGRAM INFO

  • 到達するための究極式〜x1が正しいコンジットサイズのテーブルに対して真または偽である(直径*数量= X1)のようなものです。

  • 直径は、後で追加する複数の状態(種類/数量の混合および便宜と便宜のためのケーブル種類の追加)によって異なります。

プログラム開始

import random 
import sys 
import os 

def prog01(): 
    print("") 
od = float(input("Please input the outer dimension of your wire size in decimal form: ")) 
quantity = float(input("Please choose how many cables you have: ")) 

# diameter of cabling 
def outer(od): 
    try: 
     od = float(od) 
     print (od * quantity) 
    except ValueError: 
     print ('A numeric value was not input in the program. Please only use numeric information') 

# quantity of cabling 
def number(quantity): 
    try: 
     quantity = float(quantity) 
    except ValueError: 
     print ('A numeric value was not input in the program. Please only use numeric information') 

# reference 
outer(od) 
number(quantity) 


def select_again(): 

     while True: 
      again = input("Do you have more cable types to add to your system? Please type y for yes or n for no: ") 
      if again not in {"y","n"}: 
       print("please enter valid input") 
      elif again == "n": 
       break 
      elif again == "y": 
       return prog01() 


# sizing tables - true/false statements 
x1 = (od * quantity) 

# emt_list = over 2 wires @ 40% ['.122', '.213', '.346', '.598', '.814', '1.342', '2.343', '3.538', '4.618', '5.901'] 
emt_list = ['1/2" Conduit','3/4" Conduit','1" Conduit','1&1/4" Conduit', '1&1/2" Conduit','2" Conduit','2&1/2" Conduit', 
      '3" Conduit','3&1/2" Conduit','4" Conduit',] 

if x1 <= .122: 
    print (emt_list [0]) 
elif x1 <= .213: 
    print (emt_list [1]) 
elif x1 <= .346: 
    print (emt_list [2]) 
elif x1 <= .598: 
    print (emt_list [3]) 
elif x1 <= .814: 
    print (emt_list [4]) 
elif x1 <= 1.342: 
    print (emt_list [5]) 
elif x1 <= 2.343: 
    print (emt_list [6]) 
elif x1 <= 3.538: 
    print (emt_list [7]) 
elif x1 <= 4.618: 
    print (emt_list [8]) 
elif x1 <= 5.901: 
    print (emt_list [9]) 
if x1 >= 5.902: 
    print ('You will need more than one piece of conduit') 

select_again() 

# rmc_list to come = over 2 wires @ 40% [] 
+1

ご不明な点がありましたら、それを明確にしてください。 –

答えて

0

raw_inputを使用する必要がある、あなたはあなたの選択再びループを入力したときということです'n'を入力するだけで入力ループ自体が残ります。 'y'を入力すると、prog01()関数が実行されますが、新しい行が出力され、Noneが返されるので、プログラムは再びselectループに戻ります。

関数prog01()をwhileループステートメントに置き換え、 'y'または 'n'のいずれかでyesまたはnoのクエリブレークに対してTrueループを使用する必要があります'であり、入力リターンが' n 'だった場合は、外側のループブレイクがあります。

入力クエリの末尾に.strip()。lower()を追加して、偶然のスペースを考慮して大文字と小文字の区別を削除し、raw_input()コールに変更しました。あなたのPython 2.xまたは3.xを使用している場合。あなたが3.0 +を使用している場合は、そのままinput()コールとして残すことができます。

import random 
import sys 
import os 

def outer(od): 
    try: 
     od = float(od) 
     print (od * quantity) 
    except ValueError: 
     print ('A numeric value was not input in the program. Please only use numeric information') 
def number(quantity): 
    try: 
     quantity = float(quantity) 
    except ValueError: 
     print ('A numeric value was not input in the program. Please only use numeric information') 

while True: 
    od = float(input("Please input the outer dimension of your wire size in decimal form: ")) 
    quantity = float(input("Please choose how many cables you have: ")) 

    # diameter of cabling 


    # quantity of cabling 

    # reference 
    outer(od) 
    number(quantity) 

    # sizing tables - true/false statements 
    x1 = (od * quantity) 

    # emt_list = over 2 wires @ 40% ['.122', '.213', '.346', '.598', '.814', '1.342', '2.343', '3.538', '4.618', '5.901'] 
    emt_list = ['1/2" Conduit','3/4" Conduit','1" Conduit','1&1/4" Conduit', '1&1/2" Conduit','2" Conduit','2&1/2" Conduit', 
       '3" Conduit','3&1/2" Conduit','4" Conduit',] 

    if x1 <= .122: 
     print (emt_list [0]) 
    elif x1 <= .213: 
     print (emt_list [1]) 
    elif x1 <= .346: 
     print (emt_list [2]) 
    elif x1 <= .598: 
     print (emt_list [3]) 
    elif x1 <= .814: 
     print (emt_list [4]) 
    elif x1 <= 1.342: 
     print (emt_list [5]) 
    elif x1 <= 2.343: 
     print (emt_list [6]) 
    elif x1 <= 3.538: 
     print (emt_list [7]) 
    elif x1 <= 4.618: 
     print (emt_list [8]) 
    elif x1 <= 5.901: 
     print (emt_list [9]) 
    if x1 >= 5.902: 
     print ('You will need more than one piece of conduit') 

    again = raw_input("Do you have more cable types to add to your system? Please type y for yes or n for no: ").lower().strip() 
    while True: 
     if again not in {"y","n"}: 
      print("please enter valid input") 
     else: 
      break 
    if again == "n": 
     break 


    # rmc_list to come = over 2 wires @ 40% [] 
+0

乾杯、助けてくれてありがとう! –

0

あなたがPython 2を使用している場合、あなたはあなたの現在のコードで何が起こるの代わりinput

関連する問題