0

I am newbie in python. How can I match the character ON or OFF in variable value provided by user.

In following example I want to compare only ON or OFF in the input variable in if else statement

User input will be : Authentication = ON

user_input = input("Enter the value: ")
if (user_input == "ON"):
    print("The is enable: " +user_input)
else:
    print("The is disable: " +user_input)
user2390182
  • 72,016
  • 6
  • 67
  • 89
Naik
  • 13
  • 2
  • As youre new to Python i highly recommend you not using the input like you do. But i will provide a short answer. – Raqha Oct 13 '20 at 09:48
  • You can use the statement `in` like : `user_input in ('ON','OFF')` – cedric Oct 13 '20 at 09:50
  • Thanks for the quick reply. My input is " Authentication = ON" Or " Authentication = OFF" I want read and compare only ON or OFF from the user input and print the statement using if else. – Naik Oct 13 '20 at 09:56
  • My issue resolved by below code. `user_input = input("Enter the path of your file: ") if user_input[-2:] == 'ON': print("The is enable" + "\n" +user_input) else: print("The is disable" + "\n" +user_input)` – Naik Oct 14 '20 at 17:11

0 Answers0