Home > Mobile >  How to process capitalisation in words
How to process capitalisation in words

Time:07-27

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

CodePudding user response:

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()

CodePudding user response:

You can just convert the user input into all caps 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.

  • Related