Backstory: In my previous post, I was wondering if a certain function was valid to replace another function and it was, so, I technically don't need an answer to help with with my project but I was just wondering "had I continued using sys.stdin.read() instead of input(), how would I get through one of my roadblocks?"
My issue: For some reason, when I used sys.stdin.read() it did not work with literal strings or chars. This is a lazy but working reconstruction of my code...
print("Type p or P for a pyramid")
print("Type s or S for the sum and product of two numbers")
choice_1 = sys.stdin.read()
# edge case for inputted char being invalid
if str(choice_1) != ('p' or 'P' or 's' or 'S')
err_test = 'z'
while str(err_test) != ('p' or 'P' or 's' or 'S')
print("Invalid option!)
print("Type p or P for a pyramid")
print("Type s or S for the sum and product of two numbers"
err_test = sys.stdin.read()
if err_test == ('p' or 'P' or 's' or 'S')
break
This code is roughly what I wrote. I am not writing this question at home so I couldn't copy it word for word. If you see any problems at all, please list them out, whether it's a syntax error or frowed-upon-formatting. I want to learn as much as possible but please, if you have any idea why the line right below the comment (line 6) doesn't work, please let me know! Thanks!
**Edit: ** Thank you so much for the feedback! I forgot to mention though, at one point, I tried isolating the problem so I created a new python file and created a loop that lasted forever and tested it out with only one character. I'll make it super simplified:
char = sys.stdin.read()
if char == 'a':
print("This works!")
if char != 'a':
print("This failed!)
Even this code ^^^ didn't work! Please let me know why. –