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

Voters
19. You may not vote on this poll
Page 11 of 22 FirstFirst ... 91011121321 ... LastLast
Results 101 to 110 of 217

Thread: [Beginner] Programming Challenge: 2

  1. #101
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,292
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by conehead77 View Post
    You cant quit the program
    「明後日の夕方には帰ってるからね。」


  2. #102
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by HymnToLife View Post
    Wow, that's a lof of if's
    It is the most used keyword.

    Quote Originally Posted by jimi_hendrix View Post
    just curious...could u compile C with a C++ compiler?
    If the C code is valid C++ code, you can. C++ changes the meaning of a few keywords and C has things that aren't C++, so you shouldn't do that.

  3. #103
    cprofitt's Avatar
    cprofitt is offline νόησις νοήσεως - nóesis noéseos
    Join Date
    Oct 2006
    Location
    平静
    Beans
    1,450
    Distro
    Ubuntu Development Release

    Re: [Beginner] Programming Challenge: 2

    After some reading and advice from ghostdoq76... this is my second attempt.

    Code:
    #!/usr/bin/env python
    
    #  challeng2.py
    #       A program to handle text and numeric input
    #       Version 2
    #  by PrivateVoid
    
    # variables for end statement
    
    import sys
    
    iAge = 0
    iForumID = 0
    sName = ""
    
    print "To end this program please type 'exit' at any prompt"
    
    def integertest(n):
        if n % 1 == 0:
            return True
        else:
            return False
    
    while int(iAge) < 1:
        try:
            iAge = raw_input("enter your age (must be an integer between 1 and 130) ")
            if iAge == "exit":
                sys.exit(0)
            elif int(iAge) > 130:
                iAge = 0
            elif not integertest(int(iAge)):
                iAge = 0
        except ValueError:
            iAge = 0
    
    while int(iForumID) < 1:
        try:
            iForumID = raw_input("enter your forum id (must be an integer between 1 and 999999) ")
            if iForumID == "exit":
                sys.exit(0)
            elif int(iForumID) > 999999:
                iForumID = 0
            elif not integertest(int(iForumID)):
                iForumID = 0
        except ValueError:
            iForumID = 0
    
    while sName == "":
        try:
            sName = raw_input("enter your forum name (can not begin with a space) ")
            if sName.startswith(" "):
                sName = ""
            elif sName == "exit":
                sys.exit(0)
        except ValueError:
            sName = ""
    
    print "You are ", sName, " aged ", iAge, "next year you will be ", int(iAge)+1, ", with user id ", iForumID, "the next user is ", int(iForumID)+1, "."
    A little cleaner and much shorter. Thanks dog!

    Revised this for some stuff I left out.
    Last edited by cprofitt; August 8th, 2008 at 03:03 AM.

  4. #104
    Join Date
    Jan 2008
    Beans
    4,757

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by LaRoza View Post
    It is the most used keyword.
    Most useful?

    I much prefer case or unless statements.

    But that is just me coming from a very C/Perl-ish background...

  5. #105
    cprofitt's Avatar
    cprofitt is offline νόησις νοήσεως - nóesis noéseos
    Join Date
    Oct 2006
    Location
    平静
    Beans
    1,450
    Distro
    Ubuntu Development Release

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by tinivole View Post
    Most useful?

    I much prefer case or unless statements.

    But that is just me coming from a very C/Perl-ish background...
    Perhaps I should look at this Perl you speak of.

  6. #106
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by tinivole View Post
    Most useful?

    I much prefer case or unless statements.

    But that is just me coming from a very C/Perl-ish background...
    I said "used" and it is. Most code is full of "if"'s. There was a study on it, but I leave that up to google to find.

    Quote Originally Posted by PrivateVoid View Post
    Perhaps I should look at this Perl you speak of.
    Look at it? Don't. It is gibberish. However, you can learn to write it...

  7. #107
    Join Date
    Dec 2006
    Location
    Birmingham, England
    Beans
    83
    Distro
    Ubuntu 6.06 Dapper

    Re: [Beginner] Programming Challenge: 2

    I am still very much a beginner. I do not expect to win, but just thought it was about time I let other people view my code. Despite the fact that it is probably very messy. (All comments welcome.)

    I think (hope) that is has met all the requirements. I will happily try to correct it if not. Enjoy.

    Python
    Code:
    # Introduction.
    print "Hello and Welcome to M_the_C's Fantabulous Forum Doohickey."
    print "Type 'quit' or 'exit' to terminate the program at any time."
    
    while True:
    
      # Ask the user for the required information.
      forumname = ""
      while forumname == "":
        forumname = raw_input("Please type your Forum User Name:  ")
        if forumname == "quit":
          print "Goodbye."
          exit()
        if forumname == "exit":
          print "Goodbye."
          exit()
        if forumname == "":
          "Please enter something."
        else:
          if forumname.startswith(" ") == 0:
            pass
          else:
            print "That is an incorrect answer, please try again."
            forumname = ""
        
      age = "0"
      while age == "0":
        age = raw_input("Please enter your age:  ")
        if age == "quit":
          print "Goodbye."
          exit()
        if age == "exit":
          print "Goodbye."
          exit()
        if age.isdigit() == 1:
          if int(age) < 150:
            if int(age) == 0:
              print "Sorry, you have to be 1 or older to use this program."
            else:
              pass
          else:
            print "Do you really expect me to believe that you are over 150 years old?"
            age = "0"
        else:
          print "That is an incorrect answer, please try again."
          age = "0"
    
      uid = "0"
      while uid == "0":  
        uid = raw_input("Please enter your User ID:  ")
        if uid == "quit":
          print "Why are you quitting?  You are so near the end."
          exit()
        if uid == "exit":
          print "Why are you quitting?  You are so near the end."
          exit()
        if uid.isdigit() == 1:
          if int(uid) == 0:
            print "There is no User 0, please try again."
          else:
            pass
        else:
          print "That is an incorrect answer, please try again."
          uid = "0"
    
      #  Create the extra information and format them as strings.
      age1 = int(age) + 1
      age1 = str(age1)
      uid1 = int(uid) + 1
      uid1 = str(uid1)
    
      #  Create and print the sentance.
      listA =  ["You are ", forumname, ", aged ", age, " next year you will be ", age1, ", with user id ", uid, ", the next user is ", uid1, "."]
      listB = "".join(listA)
      print listB
    
      b = "a"
      while b == "a":
        #  Ask what to do next.
        a = raw_input("Do you want to do another? y/n:  ") 
        if a == "y":
          print "Restart."
          b = "b"
          pass
        elif a == "n":
          print "Goodbye."
          exit()
        elif a == "quit":
          print "Goodbye."
          exit()
        elif a == "exit":
          print "Goodbye."
          exit()
        else:
          print "Pardon?"
    EDIT: Altered because of this.
    Last edited by M_the_C; August 8th, 2008 at 06:49 PM.

  8. #108
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: [Beginner] Programming Challenge: 2

    Quote Originally Posted by tinivole View Post
    I much prefer case or unless statements.
    Ruby has case and unless statements, and an until loop. However, unlike Perl, Ruby code is actually readable. I miss case and unless when I write Python (both contribute to code readability), even though Ruby's case statement annoyingly doesn't fall through like PHP's.

  9. #109
    Join Date
    Jan 2008
    Beans
    4,757

    Re: [Beginner] Programming Challenge: 2

    Yeah, I was thinking about taking up Ruby as my next language.

    And I don't find Perl that unreadable either.
    Would a fairly indepth knowledge of sed and awk be a reason why? I don't know...

    Quote Originally Posted by LaRoza
    I said "used" and it is.
    Ah, sorry. I could sworn it said "useful" a few hours ago...
    Quote Originally Posted by LaRoza
    Look at it? Don't. It is gibberish.
    Haha, I see you are a Python Programmer then...

  10. #110
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 2

    is there a C# ide in the repos that i could use to test to see if my code is compatable?

Page 11 of 22 FirstFirst ... 91011121321 ... 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
  •