How to process capitalisation in words

Question:

I tried to solve this problem but don’t know how to, I would appreciate it if you could help me.

criteria:
If the paint colour label contains the string ‘blue’ with any capitalisation, your program should say: ‘Excellent! We’ll soon have enough paint for the sky!’

I need to know how how to make the code register the capitalisation of the word ‘blue’

colour = input ('Which colour did you find? ')
number_of_tins = int(input('Number of tins: '))
if 'blue' in colour:
  print ("Excellent! We'll soon have enough paint for the sky!")

thank you

Asked By: muckywater

||

Answers:

You can just convert the user input into all lowercase when checking in the if statement.

if 'blue' in colour.lower()

The colour.lower() makes all the characters in colour lowercase, so you don’t really have to complicate it.

Answered By: Sai Nallani

Strings have a few methods to help you out, namely lower and upper. Typically lower is used in cases like this. It returns a new string of each letter in lowercase or uppercase respectively. So you can simply compare ‘blue’ to colour.lower()

Answered By: Anonymous4045

In the input you could use methods like colour = input ('Which colour did you find? ').lower()

it would convert all your input into lower case
even user type in capital and your program works

Answered By: kamlesh
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.