mardi 30 décembre 2014

Python I/O User Input

I am very new to Python, although I have finished the Codecademy course. I am very sorry if someone has already answered this question, as it all seems way to beyond me. The question I am trying to conquer is if you can use Python's I/O implication to test if a file contains a certain word or phrase and then to run some more code. The goal that I would want to have with this is to have all of the interaction take place in notepad. This would require some form of if statements interaction with the read function in I/O as far as I can see.


I would want to put a code along the lines of:



while True: #Using a while loop to re-ask if not valid answer.
color = input("What is your favorite color? [red/blue/green] ").lower() #Asking and converting to lowercase.
if color == "red" or color == "blue" or color == "green": #Testing if color is valid.
break #Escaping the loop
else: #If it's not valid:
print("Wow, I have never heard of " + color + " being a color before")
continue #Restarting the loop
print("Really? " + color + " is my favorite color too!") #Because they got out of the loop, we can run this.


into some form of it being in notepad. Again, I would like the question to be asked in notepad, the question to be answered by the user in notepad, and then set return some text in NOTEPAD. If you can help me, or direct me to something else that would help me with this, thanks be to you.


Aucun commentaire:

Enregistrer un commentaire