2017-05-10 15 views
0
import os.path 

#The model of the phone initialised to empty 
strModel = "" 

#Ask the user for their make 
strModel = input("What is the make?") 

#if the length of their input is too small ask them to input again 
while len(strModel) <= 4: 
    #Promot the user to input again 
    strModel = input("Not enough characters. What is the make?") 

#check if the file exists for specified phone  
if os.path.isfile(strModel + ".txt") == True: 
    #open the file 
    f = open(strModel + ".txt", "r") 
    #turn contents of file into an array of strings for each line 
    lineArray = f.readlines() 

    #loop through the array to ask and answer questions 
    for line in lineArray: 
     #check if the line we are on is a question 
     if lineArray.index(line) % 2 == 0 or lineArray.index(line) == 0: 
      question = line 
      #ask the question and wait for reply 
      userAnswer = input(question) 
      #yes means the user has that problem so print the relevant answer 
      if(userAnswer == "yes"): 
       print(lineArray[lineArray.index(line)+1]) 
else: 
    print("Your model does not exist in our database.") 

私はPythonの初心者です。どのように私はこのコードの擬似コードを書くだろう。これは、ユーザーに電話を尋ねるコードです。私はこのコードを使って効率的にできますか?このコードの擬似コード

+0

:ほとんどの面接官はあなたのコードの場合など、彼らはあなたがデータ構造を知っていることを見たいと思って、作業コードについて

を気にしない、私はそうのような擬似コードでそれを考えるだろういいえ、自分でコードを作成しました。私は初心者であるため、この特定のコードの疑似コードを作成する方法を知りたいだけです。 – Unthinkable

+1

なぜあなたはすでに持っているコードを擬似コードにしたいのですか?このコードを作成して擬似コードを作成する場合は – depperm

+0

私はちょうどこのような特定のコード用の擬似コードを作成するのに苦労します。 – Unthinkable

答えて

0

私はそれをどのように行うか教えてくれます。このようにする主な理由は、私はコンパイラではないということです。また...プログラミングクラスでは、実際のコードを書いたかったので、私はその週をスキップしました。

通常、実際のコードの書き込みを計画するために疑似コードを書きます。しかし、python IMOのような言語は、それを必要としませんでした。

とにかく;私はそれが何であってもアルゴリズムやワークフローを考える。多分それは関数です。それが関数であれば、その関数を実行するために必要なものを考え、それを素早く表す(擬似コード)してから実際のコードに変換します。もちろん、私はこのようにはしません....それは就職面接でない限り(私は再びコンパイラ/通訳/などではないからです)。

strModel <= input 

while strModel <= 4: 
    prompt 

if path_is_valid: 
    fd = open file 

    for each line in file: 
     if this or that: 
      prompt user 

      if answer is yes: 
       do that