Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:00:36+00:00 2026-05-28T04:00:36+00:00

The problem I am working on is explained below: 2.1) Write a program that

  • 0

The problem I am working on is explained below:

2.1) Write a program that asks a user to input a color.
If the color is black or white, output “The color was black or white”.
If it starts with a letter that comes after “k” in the alphabet,
output “The color starts with a letter that comes after “k” in the
alphabet”. (Optional: consider both capitalized and non-capitalized
words. Note: the order of the alphabet in Unix and Python
is: symbols, numbers, upper case letters, lower case letters.)

Here is the authors solution:

#!/usr/bin/env python
#
# guess a color
#
answer = raw_input ("Please enter a color: ")

if (answer == "black") or (answer == "white"):
 print "The color was black or white."
elif answer >= "k":
  print "The color starts with a letter that comes after \"k\" in the alphabet."

This is my answer to the problem:

#!usr/bin/env python
#
#This program asks the user to input a color

color = raw_input("Please, enter a color, any color.")

if (color == "black") or (color == "white"):
 print "The color was black or white."

elif color[0] != "a" or "b" or "c" or "d" or "e" or "f" or "g" or "h" or "i" or "j" or "k":
 print "The color starts with a letter that comes after 'k' in the alphabet."

else:
 print "The color was niether black nor white."

I am having trouble understanding how the authors solution works, specifically for identifying if, “The color starts with a letter that comes after “k” in the alphabet”.

How is does Python make this work?

elif answer >= "k":

How is Python identifying the first character, such as color[0] and the range of letters beyond k?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:00:37+00:00Added an answer on May 28, 2026 at 4:00 am

    Because in general, Python sequences (strings included) implement lexicographical ordering for their elements. So first element 0 is compared, if the same then element 1, etc.

    Note, though, that your solution is wrong. It’s parsed as (color[0] != "a") or "b" or "c" or "d" or "e" or "f" or "g" or "h" or "i" or "j" or "k", which is false only when color[0] == 'a'. You’re looking for color[0] not in ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j') (you shouldn’t exclude ‘k’, either), but using >= is just a much, much cleaner thing to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem When working with MasterPages, a common irritation I run into is that script
Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir , but I
I am working on a geometry problem that requires finding the intersection of two
I'm working on a problem that requires caching paginated search results: Paginating very large
The Problem: Exercise 2-8 of The C Programming Language, Write a function rightrot(x,n) that
I have explained the problem below this code <div id='content'> <div id='help'> blah blah
Below is the snippet of code that keeps giving me the problem. Could someone
For the problem below, I got the query working. But when I am running
I'm currently working on a program that, with the help of the selenium's webdriver
I had a problem working with the image classes in java. I am creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.