Python Practice › If-Else Programs › Program 56
Print 1 for Hello and 0 for Bye
Write a Python program that prints 1 if the user enters Hello and 0 if the user enters Bye.
Input
Hello
Output
Enter your choice: Hello 1
Approach
- Compare the cleaned input with each word.
Solution
choice = input("Enter your choice: ").strip().lower()if choice == "hello": print(1)elif choice == "bye": print(0)else: print("Please type Hello or Bye")Outputtyped input: Hello
Enter your choice: Hello 1
Line by line
Line 1
strip() removes stray spaces and lower() accepts any capitalisation.
Learn the concept
New to this topic? Read the lesson, then come back.