Re: totally lost newbie

Discussion in 'Python' started by Steve Howell, May 27, 2007.

  1. Steve Howell

    Steve Howell Guest

    --- mark <> wrote:

    > Hi all
    > I posted earlier on this but have changed my
    > approach so here is my
    > latest attempt at solving a problem. I have been
    > working on this for
    > around 12 hours straight and am still struggling
    > with it.
    > Write a program that reads the values for a random
    > list of cards from
    > a file, where each line in the file specifies a
    > single card with the
    > rank and then the suit separated by a space. The
    > rank should be an
    > integer in the range of 1 to 13 (Ace:1, King:13),
    > while the suit
    > should be a lower case character in the set { 'h',
    > 'd', 'c', 's' }.
    > Sort the card entries into suits ordered by rank,
    > and print out the
    > ordered list. Hint: sort the list first by rank, and
    > then by suit.

    Given that the hint is to sort twice, you can first
    break down the problem by just trying to sort your
    list according to the number on the card, and don't
    worry about the suit. Also, try using a data file
    that doesn't have any face cards in it, to keep things
    simple at first.

    Then, to get the face cards working, think about
    this--a Jack is really just an 11, a Queen is just a
    12, a King is just a 13, and an Ace is just a 1.

    When you read in your data, maybe you want to just
    work with the numbers internally? Do you know how to
    use a dictionary to map K to 13?

    Then, when it comes time to produce the final output,
    you'll need to map 13 back to 'K', which again
    involves using a dictionary.

    There are other approaches, too, just hope this sparks
    some thought.

    ____________________________________________________________________________________Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
    Steve Howell, May 27, 2007
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Jan 13, 2004
  2. karthik kumar

    stl errors - totally lost

    karthik kumar, Dec 3, 2004, in forum: C++
    Karl Heinz Buchegger
    Dec 3, 2004
  3. guardsman85
    Aug 29, 2006
  4. mark

    totally lost newbie

    mark, May 27, 2007, in forum: Python
    Kay Schluehr
    May 27, 2007
  5. Steve Howell

    Re: totally lost newbie

    Steve Howell, May 27, 2007, in forum: Python
    Marc 'BlackJack' Rintsch
    May 27, 2007

Share This Page