0

This is what I tried and , basically what I was trying to do was that, if a user enters other than 1,2,3,4,6 then it will go back to a=int(input.....)). But for me it keeps giving output as None.

def hi():
    while True:
        try:
            a=int(input("enter the denominator of Pi radian\n"
                "(choose from 1,2,3,4,6)\n"
                "Enter here:"))
            if a <=0 or a>=7 and a!=5:
                print("Enter the given digits")                     
            else:
                return a                       
        except Exception:
            print("enter a valid type")
ant=hi()

print(ant)              
quamrana
  • 37,849
  • 12
  • 53
  • 71

1 Answers1

0

You have applied a wrong condition here:

if a <=0 or a>=7 and a!=5:

You're checking a!=5 as a wrong input, when it should be a==5. Also apply or instead of and. Change it to:

if a <=0 or a>=7 or a==5:
devReddit
  • 2,696
  • 1
  • 5
  • 20