Python Forum
Looking for critique on my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for critique on my code
#11
So I've been working on a relatively short script for solving a math problem, and it works, but there's a specific part that I want to optimize with a procedure. However, I can't figure out how to implement one. 

print("Enter the corresponding values of the standard quadratic function: y=ax^2+bx+c")
a = input("Enter the A value:")
    if a == "stop" or a == "Stop" or a == "STOP":
        print("\nStopping program...")
        sys.exit()
b = input("Enter the B value:")
    if b == "stop" or b == "Stop" or b == "STOP":
        print("\nStopping program...")
        sys.exit()
c = input("Enter the C value:")
    if c == "stop" or c == "Stop" or c == "STOP":
        print("\nStopping program...")
        sys.exit()
Reply
#12
(May-03-2017, 04:13 PM)zeevo234 Wrote:  a = input("Enter the A value:")
    if a == "stop" or a == "Stop" or a == "STOP":

Either just force a to have a certain case, or use the in operator:
# A
if "stop" == a.lower():

# or B
if a in ("stop", "Stop", "STOP"):
A is better if you can use it, since B doesn't even catch all possibilities (what if they type StOp?)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020