-1

im trying to do url shortener tool , but im facing a problem that when the link is done and the tool will ask the user if he want to do it again

so the problem here that if user inputed n the tool won't exit

Code :

 again = input(f"{r}[?]{b}Do you want to short another link (y/n) ==> ")
 if again == 'y'or'Y':
     os.system('cls')
     logo()
     link = input(f"{r}[/]{b}Enter the link (google.com) --> ")
 elif again == 'n'or'N':
     print(f"{r}[-]{b}Thanks for using the tool !")
     exit()
 else:
     print(f"{r}[!]{b}Not a valid option")

what is the error here please help me

V E X
  • 45
  • 9

1 Answers1

0

You're not evaluating what you think you're evaluating.

if again == 'y' or 'Y':

is not the same as

if again == 'y' or again == 'Y':

in your terminal, try

if "Y":
    print(True)

you'll see that it evaluates to True. So you're always going to enter that first if statement.

Try

if again == "y" or again == "Y":

or

if again.lower() == "y":

or

if again in ["y", "Y"]:

and the same changes for the elif

lumalot
  • 141
  • 10