Question:

If statements Python question

by  |  earlier

0 LIKES UnLike

i have a question

ive noticed if you have a raw_input in python and the answer has been typed out in lower case and you wanted to accept say uppercase or half and half, the if statement doesn't seem to read it. Then if you are saying eg if question = "hello", how would you get it to accept hello in different forms like HELLO or HeLlO or helLo when your else option is say wen type in Bye, it prints something different (that is just an example)

 Tags:

   Report

2 ANSWERS


  1. The answer above's approach is correct, convert the input string to all upper case (or lower case), then compare. But the code above obviously won't work, this will (or should).

    s = raw_input()

    s = s.lower()

    if s == "hello":

    ...


  2. question = upper(question)

    if question = "HELLO"

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions