0

I am having trouble getting the proper result in this code:

class Commerce():
    def Entry(_sub, test):
        while True:
            if _sub == "Maths" or "Busines Studies" or "Accounts" or "Economics" or "Physical Education" or "English":
                try:
                    print("Enter marks of ", _sub, "in", test, end="=>")
                    x = int(input())
                except:
                    print("Invalid input")
                    continue
                if x in range(0, 41):
                    return x
                    break

                else:
                    print("Marks exceded, please try again ")
            else:
                print("Invalid marks")
                continue
class Restrict():
      def limitalnum(content):
        punctuations =['!','(',')','-','[',']','{','}',';',':',"'",'"',"\\",',','<','>','.','/','?','@','#','$','%','^','&','*','_','~']
        count=3
        while True:
            ask_input=input('%s'%content)
            if ask_input.isalnum()==False:
                count=count-1
                if count in[3,2,1]:
                    print("Sorry only alphabets and numeric are acceptable")
                    print("Remaing retry of above entry:%s"%count)
                else:
                    pass
                if count==0:
                    print("Remaing retry of above entry:%s"%count)            
                    print("We are sorry you have exhausted all retry's")
                    break
                continue
            else:
                break

Stream_option=Restrict.limitalnum("Which Stream you are currently  pursuing")
if Stream_option=='1' or 'Maths':
    MATHS_PT_MARKS=Commerce.Entry("Maths","Periodic Test-1")
elif Stream_option == '2' or 'Informatics Practices' or 'IP':
    IP_PT_MARKS=Commerce.Entry("IP","Periodic Test-1")
elif Stream_option == '3' or 'Hindi':
    HI_PT_MARKS = Commerce.Entry("Hindi","Periodic Test-1")

Output Coming: Which Stream you are currently pursuing: 2 Enter marks of Maths in Periodic Test-1=>

Output Expected : Which Stream you are currently pursuing: 2 Enter marks of IP in Periodic Test-1=>

I don't know for sure if i used if condition properly or not, Thanks

This question is not duplicate for any other questions in Stack Overflow What i am trying to get it calling a function from a class in a conditional statement

Uniqueness: If the Conditional statement is true Execute the function If the conditional statement is False Pass to next line of command

Jayant
  • 1
  • 1
  • 2
    ``if _sub == "Maths" or "Busines Studies" or "Accounts" or ...`` this does not do what yo think it does. You should use the ``in`` operator instead. Same with ``if Stream_option=='1' or 'Maths':`` and so on. – Mike Scotty Oct 21 '19 at 12:54
  • 2
    Possible duplicate of [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – Mike Scotty Oct 21 '19 at 12:56
  • Mike is right, you can't really say `if x == a or b or c ...` if you want to know if `x` is one of those elements. When you do that, python interprets it as `if (x == a) or bool(b) or bool(c) ... `. Since the boolean value of a non-empty string is always `True`, your if statements always pass. Instead, use `if x in [a, b, c, ...]` – SyntaxVoid Oct 21 '19 at 12:57
  • 1
    Comparison operators bind more tightly than boolean operators. ``Stream_option=='1' or 'Maths'`` means ``(Stream_option == '1') or 'Maths'``! – MisterMiyagi Oct 21 '19 at 12:57
  • @MikeScotty I tried using in operator but the output is still not the one i wanted – Jayant Oct 22 '19 at 13:31
  • @Jayant Unless you show that you've fixed the issue with your chained `or` operators after `==`, we can't really help you further. It may or may not be the only issue in your code, but it is definitely an issue that needs to be resolved. – glibdud Oct 22 '19 at 13:44
  • There is a big misunderstanding of classes as well. – sashaaero Oct 22 '19 at 14:09
  • Thanks everyone for all your efforts ,fortunately the problem is now solved with everyone help. For Acknowledgement Solution : In function alnum the user value was stored but never executed without executing the value , the interpreter would not understand the if condition otherwise (emphasis on above code only) , the problem was fixed when i executed the stored value using return command – Jayant Oct 22 '19 at 14:24
  • Sorry, I am new in this community so i am still on the learning curve on rules and regulations – Jayant Oct 22 '19 at 14:25
  • @sashaaero what do you mean? – Jayant Oct 23 '19 at 10:20

0 Answers0