+ 1

How to make the programmes ignore capitalization and space?

like input aac, Aac,AaC etc will give the same result.

23rd Oct 2018, 9:31 AM
Rahul Gill
Rahul Gill - avatar
5 odpowiedzi
+ 3
Did you meant in strings ? to remove spaces : print("Hello World".replace(" ","")); to equalize although cases are equal: print("A".capitalize()=="a".capitalize());
23rd Oct 2018, 9:58 AM
Googel
Googel - avatar
+ 2
name = input().lower().replace(" ", "") print(name)
23rd Oct 2018, 9:54 AM
Mike Utty
Mike Utty - avatar
+ 2
If you want the user to enter a command like chose(add, sub,mul, div) and the user enters Add if you use .lower() on the variable it converts it to lowercase and will then == add. same with .replace() it replaces the first arg with the second in this case a space " " with no space "". They are built in functions. .upper() would also work by making the input all uppercase in the case you wanted to compare it to say ADD
23rd Oct 2018, 10:06 AM
Mike Utty
Mike Utty - avatar
+ 1
you need to convert your every input into lower case or according to your need.it will produce right and same result every time. e.g x=input() print(x.lower()) #if x is ABC or AbC or abc it will always give abc. but remember that your code should be work with lower case letter.
23rd Oct 2018, 10:12 AM
Maninder $ingh
Maninder $ingh - avatar
0
can you explain
23rd Oct 2018, 9:59 AM
Rahul Gill
Rahul Gill - avatar