View Poll Results: Who do you think is the best beginner?

Voters
19. You may not vote on this poll
Page 1 of 22 12311 ... LastLast
Results 1 to 10 of 217

Thread: [Beginner] Programming Challenge: 2

  1. #1
    Join Date
    Apr 2007
    Beans
    14,781

    [Beginner] Programming Challenge: 2

    The last challenge was very popular with many entries. Hopefully, the comments and other code was informative. Here is the last challenge: http://ubuntuforums.org/showthread.php?t=876479

    For this one, I ask non beginners to not give solutions that give away too many hints to those trying.


    The Challenge:
    The most problematic part of programming is user input. The best program can fall apart because of users. No matter what you ask in a program, expect the user to give random input or nothing at all. One of the entries in the previous challenge was disqualified because as I tested the code (before reading it, to see if it did what it was supposed to do), I was confronted with a vague prompt. It didn't really give an indication of what I was supposed to enter. I entered nothing, and exception was thrown because the program tried to read a part of the string and the program ended.

    Another one asked for input, but kept looping, no way to cancel it!

    I suggest you all read this article: Saving Users From Themselves

    It is using Python as the language, so entries using Python will have a good guide to follow, but any language is allowed (and somewhat prefered for this challenge)

    Write a program to take a person's forum name, age, forum user id (a postive integer equal to or between 1 and 999999). The program should ask for each datum individually, and not go to the next unless the previous was valid. If there is an error, it must prompt again until it is write or the program is halted. The entry "quit" should exit the program at any question.

    If all data is entered, it should print a sentence like:
    Code:
    You are LaRoza, aged 20 next year you will be 21, with user id 266234, the next user is 266235.
    In short:
    • User name can't begin with spaces, or have no characters in it. It can truncate strings over 20, if needed.
    • Age has to be positive and not 0. It doesn't need a maximum, but you are free to make your program logical.
    • User ID can't be negative or 0. The maximum I require is 999999.
    • Typing "exit" should exit the program gracefully.
    • The prompt should be logical.
    • Most importantly, it must not crash, segfault, lockup, or enter an infinite loop no matter what is entered



    Rules:
    Do not copy code, but you can obviously read it

    Try not to comment on other submissions. It will be hard to judge changing entries. If you edit your code, post the new version and make it clear there is a new code.

    How it will be judged
    This task is a bit more about programming than the previous, so you'll be judged on how ell the program works.

    • If I can segfault it, it is disqualified. (hint, C users have a big challenge, but if it works, you are almost guaranteed to win. Input in C is not trivial. To make this simpler, I will not enter a string bigger than 20 characters for valid data, but larger strings shouldn't cause problems. Truncate them.)
    • If I can make it throw an exception that is not caught and handled, it is disqualified (Python users, you can test data and catch exceptions, I recommend both)
    • Unicode is not required, but if there are many entries in the final judging, unicode will be the tie breaker (use the first part of my title before the | to test)
    • If I can't exit the program without killing it, it will be disqualified.
    • Prompts should be logical and tell how to exit.


    As before, try to follow the following (although I think it won't come down to judging on this, as the challenge will be tricky for beginners):
    • Clean code. Readable code is a must for being a programmer who wishes to possibly interact with others. Some languages can be more readable than others, so it will be judged on the effort of writing clean code, not which language is easier to read by design.
    • Logical code. Be a programmer, not a code monkey
    • Commented code. If something is possibly unclear (like an obscure use of math), let the readers know. Do not over comment, and let the code speak for itself whenever you can. Have logical variable names and function names. (Excessive commenting is a minus factor)
    • Working code. It has to work as it is posted. The codw will be read on the forum, so remember to use this guide to paste code if you don't know how: http://ubuntuforums.org/showthread.php?t=606009


    Hints:
    • If you use C, be wary of input functions. I recommend getting everything as a string and testing it.
    • Since you will be performing math on the data, you should watch out for illogical answers. All numbers will be integers, so watch out for large numbers! I shouldn't get infinity or 0 anywhere!
    • Using this challenge to try out a new language brings you bonus points, so please state when you are using the language for the first time if you are.
    Last edited by LaRoza; August 6th, 2008 at 03:46 AM.

  2. #2
    Join Date
    Feb 2008
    Location
    Cape Town, South Africa
    Beans
    Hidden!
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: [Beginner] Programming Challenge: 2

    Just want to start it off and say good, Luck to all and Thanks again LaRoza

  3. #3
    Join Date
    Jan 2007
    Beans
    343
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by LaRoza View Post
    Prompts should be logical and tell how to exit.
    "To exit, just hold down escape, control, tab, alt, both shifts, num lock and the little squiggly until your screen turns blue. Then, stare at it until your shift ends."

    (courtesy of Strong Bad)

    But, kidding aside, any plans for programming challenges for the more advanced programmer geeks?

  4. #4
    Join Date
    Feb 2008
    Location
    Cape Town, South Africa
    Beans
    Hidden!
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by kpatz View Post
    "To exit, just hold down escape, control, tab, alt, both shifts, num lock and the little squiggly until your screen turns blue. Then, stare at it until your shift ends."

    (courtesy of Strong Bad)

    But, kidding aside, any plans for programming challenges for the more advanced programmer geeks?
    I don't think it is fair to expect her to do those as well Maybe some one else has the time would be willing to take them on.

  5. #5
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by kpatz View Post
    But, kidding aside, any plans for programming challenges for the more advanced programmer geeks?
    http://ubuntuforums.org/showthread.php?t=783387

    http://ubuntuforums.org/showpost.php...8&postcount=18

    The older list was more advanced, but the index is now out of date, and no one has continued the challenges. Feel free to pick them up.

  6. #6
    Join Date
    Feb 2007
    Location
    Edinburgh, Scotland
    Beans
    391

    Re: [Beginner] Programming Challenge: 2

    Im almost certain there are cleaner ways to do this. Anyway, here is my attempt in Python:
    Code:
    #!/usr/bin/env python
    
    import sys
    
    class User:
    
        #Sets up variables for the class & prints banner
        def __init__(self):
            self.username = ""
            self.age = 0
            self.uid = 0
            
            #Print a quick set of instructions so people dont get lost 
            print "Please fill in the correct data or type exit to quit"
            
        #Checks to see if the user wants to quit
        def check_quit(self, uinput):
            if uinput== "exit":
                sys.exit(0)
    
    
        #Gets the users forum username
        def get_username(self):
            user_input = raw_input("Type your forum username: ")
        
            self.check_quit(user_input)
        
            #Check string is correct length
            if len(user_input) > 20:
                print "Usernames must be less than 20 characters long"
                self.get_username()
            elif len(user_input) < 1:
                print "Usernames must be at least 1 character long"
                self.get_username()
            else:
                #Use exception handling to detect if user is giving invalid data
                try:
                    self.username = str(user_input)
                except:
                    print "Username must be in string format"
                    self.get_username()
               
        #Gets the users age     
        def get_age(self):
            user_input = raw_input("Type your age: ")
    
            self.check_quit(user_input)
            
            #Convert the output of range() to string so we can convert safely
            #to integer (with error handling) later on
            if user_input not in str(range(1, 999999)):
                print "Please enter a number between 1 and 999999"
                self.get_age()
            else:
                try:
                    self.age = int(user_input)
                except:
                    print "Please enter a number between 1 and 999999"
                    self.get_age()
               
        #Gets the users forum user id     
        def get_uid(self):
            user_input = raw_input("Type your forum user id: ")
    
            self.check_quit(user_input)
    
            #Convert the output of range() to string so we can convert safely
            #to integer (with error handling) later on      
            if user_input not in str(range(1, 999999)):
                print "Please enter a number between 1 and 999999"
                self.get_uid()
            else:
                try:
                    self.uid = int(user_input)
                except:
                    print "Please enter a number between 1 and 999999"
                    self.get_uid()
                    
        #Shows the final string
        def show_string(self):
            print "You are %s, aged %s next year you will be %s, with user id %s, the next user is %s." % (
                  self.username, self.age, self.age + 1, self.uid, self.uid + 1)
    
    if __name__ == "__main__":
        usr = User()
        usr.get_username()
        usr.get_age()
        usr.get_uid()
        usr.show_string()
    Today we have 15 minutes of fame, tomorrow 15 minutes of anonymity.
    My Blog | Veza - Opensource TinyURL clone with sensible URLs

  7. #7
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Remember: 0 isn't valid as an age or id, and ages have to be realistic. Also, names can be over 20, but they can be truncated (this is for C programmers mainly). Python doesn't have this issue really, so you can accept longer user names.

  8. #8
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by kpatz View Post
    "To exit, just hold down escape, control, tab, alt, both shifts, num lock and the little squiggly until your screen turns blue. Then, stare at it until your shift ends."

    (courtesy of Strong Bad)

    But, kidding aside, any plans for programming challenges for the more advanced programmer geeks?
    heh, I just wrote LaRoza a message regarding advanced challenges.
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  9. #9
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by kpatz View Post
    "To exit, just hold down escape, control, tab, alt, both shifts, num lock and the little squiggly until your screen turns blue. Then, stare at it until your shift ends."

    (courtesy of Strong Bad)

    what does this do...

    and i have a questions...

    if i enter the max id number (99999 i think it was) should it say "the next user will be 100000" or "you are the last user"

  10. #10
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by jimi_hendrix View Post
    if i enter the max id number (99999 i think it was) should it say "the next user will be 100000" or "you are the last user"
    999999 (6 digits).

    No, it can go beyond, it just has to accept at least that amount and there will be no penalty for not accepting longer numbers.

Page 1 of 22 12311 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •