25.3k views
1 vote
Input a word. If it is "orange," print "Correct." Otherwise, print "Nope". What happens if you type in "ORANGE" or "OrANGE?" Does the capitalizing make a difference?

Sample Run 1
What color? orange
Sample Output 1
Correct
Sample Run 2
What color? red
Sample Output 2
Nope

User Mell
by
4.9k points

2 Answers

4 votes

Final answer:

Typing in "ORANGE" or "OrANGE" when the expected word is "orange" will result in "Nope" because string comparisons are typically case-sensitive, and thus capitalization does matter.

Step-by-step explanation:

When the task is to input a word and print "Correct" if the word is "orange," and print "Nope" otherwise, it is implied that the word must match exactly. Therefore, if you type in "ORANGE" or "OrANGE," the output would be "Nope" because the capitalization does not match the word "orange" as it was specified in the instructions. This is because in most programming languages, string comparisons are case-sensitive by default, meaning "orange", "ORANGE", and "OrANGE" are seen as different strings.

User Garrettmac
by
5.6k points
7 votes

Answer:

Yes, the capitalization does make a difference.

Step-by-step explanation:

The program will check specifically for "orange", if the input is not the same, it will return "Nope".

To prevent this from happening, you can set the input to lowercase before comparing it with "orange".

User Vvvvv
by
4.4k points