Ich muss den Benutzer nach einer Eingabe fragen (welches Problem hast du?) Ich erstellte eine Datei, die die möglichen Probleme auch hat Als mögliche Lösungen für diese Probleme. Das Programm sollte die Lösung ausdrucken, wenn die Benutzereingabe das Schlüsselwort in die Datei eingibt. Hier ist der Code:Wie passe ich die Benutzereingabe mit Schlüsselwörtern in meiner Textdatei an und gebe eine Ausgabe
print ("welcome to our automated trouble shooting system")
def do_again():
datadict = {}
with open('prosol.txt') as file:
for rec in file:
rec = rec.split(':')
problem = rec[0]
answer = rec[1]
problem = problem.split(" ")
for item in problem:
datadict[item] = answer
user_problem = input('What is the problem?: ')
print(datadict[user_problem])
repeat = input("do you have any other problems.\n1. Yes\n2. No\n")
try_again = ["1","2"]
while repeat not in try_again:
repeat = input("do you have any other problems.(please answer using the corrinsponding numbers)\n1. Yes\n2. No\n")
if repeat == "1":
(do_again())
elif repeat == "2":
print("bye. i hope it helped you")
quit()
(do_again())
es funktioniert, wenn ich ein Wort Schlüsselwörter verwende. zum Beispiel
welcome to our automated trouble shooting system
What is the problem?: **screen**
if your screen is broken, then you will have to replace it. if it is frozen the try turning off your phone and the turn it on again.
do you have any other problems.
1. Yes
2. No
aber es funktioniert nicht, wenn ich
welcome to our automated trouble shooting system
What is the problem?: **my screen doesnt work**
Traceback (most recent call last):
File "C:\Users\hp\Downloads\task2\mine\task 2.py", line 38, in <module>
(do_again()) ##calling the function
File "C:\Users\hp\Downloads\task2\mine\task 2.py", line 18, in do_again
print(datadict[user_problem]) ##print the value of the kye selected
KeyError: 'my screen doesnt work'
ich so das Gefühl, ein volles sentence.for Beispiel setzen geschieht, weil ich einen dictonary verwende. Obwohl ich weiß, dass dies der Rerason ist, weiß ich nicht, wie ich es beheben kann. kann jemand mir helfen pls. hier ist die Datei nur, wenn Sie es brauchen:
screen Screen SCREEN display Display DISPLAY : if your screen is broken, then you will have to replace it. if it is frozen the try turning off your phone and the turn it on again.
battery Battery BATTERY power Power POWER : if your phone is out of charge and you cant seem to charge it then you will have to replace either your battery or charger.
audio Audio AUDIO sound Sound SOUND : to fix you sound you can go to settings, then display. there you can change the setting of your devices sound
ich bin auch ein Neuling in Python. also musst du mich mit deinen Erklärungen ertragen
: Statt für viele verschiedene Gehäusevarianten eines einzelnen Wortes zu prüfen , verwenden Sie ['str.lower'] (https://docs.python.org/3/library/stdtypes.html#str.lower), um nur die Eingabe in Kleinbuchstaben zu vergleichen. zB: 'if input ("> ") .lower() == 'screen'' –