python 3.x - I want when the user input is 'y' for yes, a text file will be made, and when the input is 'n', no text file to be made -
essentially, want when user answers 'y' question, script output text file, , when user answers 'n', no go on on, not making text file. example:
print('do python? (y/n)') logask = input() if 'logask' == 'y': file = open("testlog.txt", "w") file.write("thanks feedback!") file.close() else: print('oh, that\'s bad...')
but when run this, outputs 'else' response if reply 'y'.
you comparing 2 strings. should
print('do python? (y/n)') logask = input() if logask == 'y': file = open("testlog.txt", "w") file.write("thanks feedback!") file.close() else: print('oh, that\'s bad...')
also, may want append instead of overwriting file = open("testlog.txt","a")
. if create file ahead of time, you'll know how many times answered.
python-3.x text input output
No comments:
Post a Comment