私はPythonを学び、テキストファイルから行を読み込むように設定した単純なアプリケーションを作成しようとしています。最初の行は質問で、2行目は答えです。今、私は質問と答えを読むことができます。しかし、私は実際の答えとユーザーの答えを比較する部分は、入力された答えが正しい場合でも、ループ内のアクションを実行しません。 マイコード:ループを処理しません
def populate():
print("**************************************************************************************************************")
f=open("d:\\q.txt")
questionList=[]
b = 1
score=0
start=0
for line in f.read().split("\n"):
questionList.append(line)
while b<len(questionList):
a = questionList[start]
print(a)
userinput=input("input user")
answer=questionList[b]
b = b + 2
print(answer)
if userinput==answer:
score =score+1
print(score)
else:
break
start += 2
は、私は本当にこの上の任意の指導をお願い申し上げます。 マイq.txtファイル:
1. Set of instructions that you write to tell a computer what to do.
Program
2. A language's set of rules.
Syntax
3. Describes the programs that operate the computer.
System Software
4.To achieve a working program that accomplishes its intended tasks by removing all syntax and logical errors from the program
Debugging
5.a program that creates and names computer memory locations and can hold values, and write a series of steps or operations to manipulate those values
Procedural Program
6. The named computer memory locations.
Variables
7. The style of typing the first initial of an identifier in lowercase and making the initial of the second word uppercase. -- example -- "payRate"
Camel Casing
8. Individual operations within a computer program that are often grouped together into logical units.
Methods
9. This is an extension of procedural programming in terms of using variables and methods, but it focuses more on objects.
Object Oriented Programming
10. A concrete entity that has behaviors and attributes.
Objects
? – rassar
ユーザーの入力と回答の周りの追加の空白のようなものを確認してください。それが適切だと思うなら '.strip()'を使ってください。デバッグの目的で、各ループのすべての変数を表示するか、pdbを使用してより多くのインタラクティブなデバッグを行います。 – bheklilr
@rassar私のファイルは.txt形式です。 – singha4086