View Poll Results: Who was the best beginner?

Voters
41. You may not vote on this poll
Page 6 of 27 FirstFirst ... 4567816 ... LastLast
Results 51 to 60 of 268

Thread: [Beginner] Programming Challenge: 1

  1. #51
    Join Date
    Nov 2007
    Location
    Georgia, United States
    Beans
    465
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [Beginner] Programming Challenge: 1

    Whoops, found the answer to my question.
    Ubuntu Beginners Team - Development Focus Group Leader
    Ubuntu Georgia Local Team - Website Administrator
    Ubuntu Forums Unanswered Posts Team - Leader

  2. #52
    Join Date
    Nov 2007
    Location
    Georgia, United States
    Beans
    465
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [Beginner] Programming Challenge: 1

    Here is a simple one done in Bash:
    Code:
    #/usr/bin/bash
    #These are the lyrics to the rhyme "99 Bottles of Beer on the wall, coding 
    #done in bash
    echo 99 bottles of beer on the wall, 99 bottles of beer.
    echo Take one down and pass it around, 98 bottles of beer on the wall.
    sleep 4
    echo 98 bottles of beer on the wall, 98 bottles of beer.
    echo Take one down and pass it around, 97 bottles of beer on the wall.
    sleep 4
    echo 97 bottles of beer on the wall, 97 bottles of beer.
    echo Take one down and pass it around, 96 bottles of beer on the wall.
    sleep 4
    echo 96 bottles of beer on the wall, 96 bottles of beer.
    echo Take one down and pass it around, 95 bottles of beer on the wall.
    sleep 4
    echo 95 bottles of beer on the wall, 95 bottles of beer.
    echo Take one down and pass it around, 94 bottles of beer on the wall.
    sleep 4
    echo 94 bottles of beer on the wall, 94 bottles of beer.
    echo Take one down and pass it around, 93 bottles of beer on the wall.
    sleep 4
    echo 93 bottles of beer on the wall, 93 bottles of beer.
    echo Take one down and pass it around, 92 bottles of beer on the wall.
    sleep 4
    echo 92 bottles of beer on the wall, 92 bottles of beer.
    echo Take one down and pass it around, 91 bottles of beer on the wall.
    sleep 4
    echo 91 bottles of beer on the wall, 91 bottles of beer.
    echo Take one down and pass it around, 90 bottles of beer on the wall.
    sleep 4
    echo 90 bottles of beer on the wall, 90 bottles of beer.
    echo Take one down and pass it around, 89 bottles of beer on the wall.
    sleep 4
    echo 89 bottles of beer on the wall, 89 bottles of beer.
    echo Take one down and pass it around, 88 bottles of beer on the wall.
    sleep 4
    echo 88 bottles of beer on the wall, 88 bottles of beer.
    echo Take one down and pass it around, 87 bottles of beer on the wall.
    sleep 4
    echo 87 bottles of beer on the wall, 87 bottles of beer.
    echo Take one down and pass it around, 86 bottles of beer on the wall.
    sleep 4
    echo 86 bottles of beer on the wall, 86 bottles of beer.
    echo Take one down and pass it around, 85 bottles of beer on the wall.
    sleep 4
    echo 85 bottles of beer on the wall, 85 bottles of beer.
    echo Take one down and pass it around, 84 bottles of beer on the wall.
    sleep 4
    echo 84 bottles of beer on the wall, 84 bottles of beer.
    echo Take one down and pass it around, 83 bottles of beer on the wall.
    sleep 4
    echo 83 bottles of beer on the wall, 83 bottles of beer.
    echo Take one down and pass it around, 82 bottles of beer on the wall.
    sleep 4
    echo 82 bottles of beer on the wall, 82 bottles of beer.
    echo Take one down and pass it around, 81 bottles of beer on the wall.
    sleep 4
    echo 81 bottles of beer on the wall, 81 bottles of beer.
    echo Take one down and pass it around, 80 bottles of beer on the wall.
    sleep 4
    echo 80 bottles of beer on the wall, 80 bottles of beer.
    echo Take one down and pass it around, 79 bottles of beer on the wall.
    sleep 4
    echo 79 bottles of beer on the wall, 79 bottles of beer.
    echo Take one down and pass it around, 78 bottles of beer on the wall.
    sleep 4
    echo 78 bottles of beer on the wall, 78 bottles of beer.
    echo Take one down and pass it around, 77 bottles of beer on the wall.
    sleep 4
    echo 77 bottles of beer on the wall, 77 bottles of beer.
    echo Take one down and pass it around, 76 bottles of beer on the wall.
    sleep 4
    echo 76 bottles of beer on the wall, 76 bottles of beer.
    echo Take one down and pass it around, 75 bottles of beer on the wall.
    sleep 4
    echo 75 bottles of beer on the wall, 75 bottles of beer.
    echo Take one down and pass it around, 74 bottles of beer on the wall.
    sleep 4
    echo 74 bottles of beer on the wall, 74 bottles of beer.
    echo Take one down and pass it around, 73 bottles of beer on the wall.
    sleep 4
    echo 73 bottles of beer on the wall, 73 bottles of beer.
    echo Take one down and pass it around, 72 bottles of beer on the wall.
    sleep 4
    echo 72 bottles of beer on the wall, 72 bottles of beer.
    echo Take one down and pass it around, 71 bottles of beer on the wall.
    sleep 4
    echo 71 bottles of beer on the wall, 71 bottles of beer.
    echo Take one down and pass it around, 70 bottles of beer on the wall.
    sleep 4
    echo 70 bottles of beer on the wall, 70 bottles of beer.
    echo Take one down and pass it around, 69 bottles of beer on the wall.
    sleep 4
    echo 69 bottles of beer on the wall, 69 bottles of beer.
    echo Take one down and pass it around, 68 bottles of beer on the wall.
    sleep 4
    echo 68 bottles of beer on the wall, 68 bottles of beer.
    echo Take one down and pass it around, 67 bottles of beer on the wall.
    sleep 4
    echo 67 bottles of beer on the wall, 67 bottles of beer.
    echo Take one down and pass it around, 66 bottles of beer on the wall.
    sleep 4
    echo 66 bottles of beer on the wall, 66 bottles of beer.
    echo Take one down and pass it around, 65 bottles of beer on the wall.
    sleep 4
    echo 65 bottles of beer on the wall, 65 bottles of beer.
    echo Take one down and pass it around, 64 bottles of beer on the wall.
    sleep 4
    echo 64 bottles of beer on the wall, 64 bottles of beer.
    echo Take one down and pass it around, 63 bottles of beer on the wall.
    sleep 4
    echo 63 bottles of beer on the wall, 63 bottles of beer.
    echo Take one down and pass it around, 62 bottles of beer on the wall.
    sleep 4
    echo 62 bottles of beer on the wall, 62 bottles of beer.
    echo Take one down and pass it around, 61 bottles of beer on the wall.
    sleep 4
    echo 61 bottles of beer on the wall, 61 bottles of beer.
    echo Take one down and pass it around, 60 bottles of beer on the wall.
    sleep 4
    echo 60 bottles of beer on the wall, 60 bottles of beer.
    echo Take one down and pass it around, 59 bottles of beer on the wall.
    sleep 4
    echo 59 bottles of beer on the wall, 59 bottles of beer.
    echo Take one down and pass it around, 58 bottles of beer on the wall.
    sleep 4
    echo 58 bottles of beer on the wall, 58 bottles of beer.
    echo Take one down and pass it around, 57 bottles of beer on the wall.
    sleep 4
    echo 57 bottles of beer on the wall, 57 bottles of beer.
    echo Take one down and pass it around, 56 bottles of beer on the wall.
    sleep 4
    echo 56 bottles of beer on the wall, 56 bottles of beer.
    echo Take one down and pass it around, 55 bottles of beer on the wall.
    sleep 4
    echo 55 bottles of beer on the wall, 55 bottles of beer.
    echo Take one down and pass it around, 54 bottles of beer on the wall.
    sleep 4
    echo 54 bottles of beer on the wall, 54 bottles of beer.
    echo Take one down and pass it around, 53 bottles of beer on the wall.
    sleep 4
    echo 53 bottles of beer on the wall, 53 bottles of beer.
    echo Take one down and pass it around, 52 bottles of beer on the wall.
    sleep 4
    echo 52 bottles of beer on the wall, 52 bottles of beer.
    echo Take one down and pass it around, 51 bottles of beer on the wall.
    sleep 4
    echo 51 bottles of beer on the wall, 51 bottles of beer.
    echo Take one down and pass it around, 50 bottles of beer on the wall.
    sleep 4
    echo 50 bottles of beer on the wall, 50 bottles of beer.
    echo Take one down and pass it around, 49 bottles of beer on the wall.
    sleep 4
    echo 49 bottles of beer on the wall, 49 bottles of beer.
    echo Take one down and pass it around, 48 bottles of beer on the wall.
    sleep 4
    echo 48 bottles of beer on the wall, 48 bottles of beer.
    echo Take one down and pass it around, 47 bottles of beer on the wall.
    sleep 4
    echo 47 bottles of beer on the wall, 47 bottles of beer.
    echo Take one down and pass it around, 46 bottles of beer on the wall.
    sleep 4
    echo 46 bottles of beer on the wall, 46 bottles of beer.
    echo Take one down and pass it around, 45 bottles of beer on the wall.
    sleep 4
    echo 45 bottles of beer on the wall, 45 bottles of beer.
    echo Take one down and pass it around, 44 bottles of beer on the wall.
    sleep 4
    echo 44 bottles of beer on the wall, 44 bottles of beer.
    echo Take one down and pass it around, 43 bottles of beer on the wall.
    sleep 4
    echo 43 bottles of beer on the wall, 43 bottles of beer.
    echo Take one down and pass it around, 42 bottles of beer on the wall.
    sleep 4
    echo 42 bottles of beer on the wall, 42 bottles of beer.
    echo Take one down and pass it around, 41 bottles of beer on the wall.
    sleep 4
    echo 41 bottles of beer on the wall, 41 bottles of beer.
    echo Take one down and pass it around, 40 bottles of beer on the wall.
    sleep 4
    echo 40 bottles of beer on the wall, 40 bottles of beer.
    echo Take one down and pass it around, 39 bottles of beer on the wall.
    sleep 4
    echo 39 bottles of beer on the wall, 39 bottles of beer.
    echo Take one down and pass it around, 38 bottles of beer on the wall.
    sleep 4
    echo 38 bottles of beer on the wall, 38 bottles of beer.
    echo Take one down and pass it around, 37 bottles of beer on the wall.
    sleep 4
    echo 37 bottles of beer on the wall, 37 bottles of beer.
    echo Take one down and pass it around, 36 bottles of beer on the wall.
    sleep 4
    echo 36 bottles of beer on the wall, 36 bottles of beer.
    echo Take one down and pass it around, 35 bottles of beer on the wall.
    sleep 4
    echo 35 bottles of beer on the wall, 35 bottles of beer.
    echo Take one down and pass it around, 34 bottles of beer on the wall.
    sleep 4
    echo 34 bottles of beer on the wall, 34 bottles of beer.
    echo Take one down and pass it around, 33 bottles of beer on the wall.
    sleep 4
    echo 33 bottles of beer on the wall, 33 bottles of beer.
    echo Take one down and pass it around, 32 bottles of beer on the wall.
    sleep 4
    echo 32 bottles of beer on the wall, 32 bottles of beer.
    echo Take one down and pass it around, 31 bottles of beer on the wall.
    sleep 4
    echo 31 bottles of beer on the wall, 31 bottles of beer.
    echo Take one down and pass it around, 30 bottles of beer on the wall.
    sleep 4
    echo 30 bottles of beer on the wall, 30 bottles of beer.
    echo Take one down and pass it around, 29 bottles of beer on the wall.
    sleep 4
    echo 29 bottles of beer on the wall, 29 bottles of beer.
    echo Take one down and pass it around, 28 bottles of beer on the wall.
    sleep 4
    echo 28 bottles of beer on the wall, 28 bottles of beer.
    echo Take one down and pass it around, 27 bottles of beer on the wall.
    sleep 4
    echo 27 bottles of beer on the wall, 27 bottles of beer.
    echo Take one down and pass it around, 26 bottles of beer on the wall.
    sleep 4
    echo 26 bottles of beer on the wall, 26 bottles of beer.
    echo Take one down and pass it around, 25 bottles of beer on the wall.
    sleep 4
    echo 25 bottles of beer on the wall, 25 bottles of beer.
    echo Take one down and pass it around, 24 bottles of beer on the wall.
    sleep 4
    echo 24 bottles of beer on the wall, 24 bottles of beer.
    echo Take one down and pass it around, 23 bottles of beer on the wall.
    sleep 4
    echo 23 bottles of beer on the wall, 23 bottles of beer.
    echo Take one down and pass it around, 22 bottles of beer on the wall.
    sleep 4
    echo 22 bottles of beer on the wall, 22 bottles of beer.
    echo Take one down and pass it around, 21 bottles of beer on the wall.
    sleep 4
    echo 21 bottles of beer on the wall, 21 bottles of beer.
    echo Take one down and pass it around, 20 bottles of beer on the wall.
    sleep 4
    echo 20 bottles of beer on the wall, 20 bottles of beer.
    echo Take one down and pass it around, 19 bottles of beer on the wall.
    sleep 4
    echo 19 bottles of beer on the wall, 19 bottles of beer.
    echo Take one down and pass it around, 18 bottles of beer on the wall.
    sleep 4
    echo 18 bottles of beer on the wall, 18 bottles of beer.
    echo Take one down and pass it around, 17 bottles of beer on the wall.
    sleep 4
    echo 17 bottles of beer on the wall, 17 bottles of beer.
    echo Take one down and pass it around, 16 bottles of beer on the wall.
    sleep 4
    echo 16 bottles of beer on the wall, 16 bottles of beer.
    echo Take one down and pass it around, 15 bottles of beer on the wall.
    sleep 4
    echo 15 bottles of beer on the wall, 15 bottles of beer.
    echo Take one down and pass it around, 14 bottles of beer on the wall.
    sleep 4
    echo 14 bottles of beer on the wall, 14 bottles of beer.
    echo Take one down and pass it around, 13 bottles of beer on the wall.
    sleep 4
    echo 13 bottles of beer on the wall, 13 bottles of beer.
    echo Take one down and pass it around, 12 bottles of beer on the wall.
    sleep 4
    echo 12 bottles of beer on the wall, 12 bottles of beer.
    echo Take one down and pass it around, 11 bottles of beer on the wall.
    sleep 4
    echo 11 bottles of beer on the wall, 11 bottles of beer.
    echo Take one down and pass it around, 10 bottles of beer on the wall.
    sleep 4
    echo 10 bottles of beer on the wall, 10 bottles of beer.
    echo Take one down and pass it around, 9 bottles of beer on the wall.
    sleep 4
    echo 9 bottles of beer on the wall, 9 bottles of beer.
    echo Take one down and pass it around, 8 bottles of beer on the wall.
    sleep 4
    echo 8 bottles of beer on the wall, 8 bottles of beer.
    echo Take one down and pass it around, 7 bottles of beer on the wall.
    sleep 4
    echo 7 bottles of beer on the wall, 7 bottles of beer.
    echo Take one down and pass it around, 6 bottles of beer on the wall.
    sleep 4
    echo 6 bottles of beer on the wall, 6 bottles of beer.
    echo Take one down and pass it around, 5 bottles of beer on the wall.
    sleep 4
    echo 5 bottles of beer on the wall, 5 bottles of beer.
    echo Take one down and pass it around, 4 bottles of beer on the wall.
    sleep 4
    echo 4 bottles of beer on the wall, 4 bottles of beer.
    echo Take one down and pass it around, 3 bottles of beer on the wall.
    sleep 4
    echo 3 bottles of beer on the wall, 3 bottles of beer.
    echo Take one down and pass it around, 2 bottles of beer on the wall.
    sleep 4
    echo 2 bottles of beer on the wall, 2 bottles of beer.
    echo Take one down and pass it around, 1 bottle of beer on the wall.
    sleep 4
    echo 1 bottle of beer on the wall, 1 bottle of beer.
    echo Take one down and pass it around, no more bottles of beer on the wall.
    sleep 3
    echo No beer, go buy more!
    echo Add the beer to the wall, 99 bottles of beer on the wall.
    And i didnt copy from the website, if you are wondering that.
    Ubuntu Beginners Team - Development Focus Group Leader
    Ubuntu Georgia Local Team - Website Administrator
    Ubuntu Forums Unanswered Posts Team - Leader

  3. #53
    Join Date
    Jul 2008
    Beans
    9

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by LaRoza View Post
    ...it would be nice if people gave their input on other people's code at the end to help.
    That would be really cool if people gave their input. I know I'd definitely benefit from having people critique my code. I'm not too horrible at writing working code, but it's generally not pretty

  4. #54
    Join Date
    Jun 2008
    Location
    California, USA
    Beans
    1,030
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 1

    Here's mine, remember that I'm just learning Python so don't eat me if I'm doing this all wrong .
    PHP Code:
    #!/usr/bin/env python


    lineOne "%i bottles of beer on the wall, %i bottles of beer."
    lineTwo "Take one down and pass it around, %i bottles of beer on the wall.\n\n"
    numberOfBeers 99

    while numberOfBeers >= 0:

        print 
    lineOne % (numberOfBeersnumberOfBeers)
        print 
    lineTwo int(numberOfBeers 1)
        
    numberOfBeers -= 1

        
    #In the next three blocks, we change the output so the ending of the song makes sense.

        
    if numberOfBeers == 2:

            print 
    lineOne % (numberOfBeersnumberOfBeers)
            print 
    "Take one down and pass it around, %i bottle of beer on the wall.\n\n" int(numberOfBeers 1)
            
    numberOfBeers -= 1

        
    if numberOfBeers == 1:

            print 
    "%i bottle of beer on the wall, %i bottle of beer." % (numberOfBeersnumberOfBeers)
            print 
    "Take one down and pass it around, no more bottles of beer on the wall.\n\n"
            
    numberOfBeers 0

        
    if numberOfBeers == 0:

            print 
    "No more bottles of beer on the wall, no more bottles of beer."
            
    print "Go to the store and buy some more, 99 bottles of beer on the wall.\n\n"
            
    #Takes us out of the while loop
            
    break 
    Last edited by OutOfReach; August 2nd, 2008 at 08:49 PM. Reason: Syntax Highlighting

    Blog | I'm available for programming contributions. C & Python.
    Intel Core i7 920 | EVGA x58 SLI | NVidia GeForce 8600 GT | WD 500GB HDD | Corsair XMS3 3GB | Ubuntu 9.04

  5. #55
    Join Date
    Sep 2006
    Beans
    2,914

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by Hellow View Post
    Here is a simple one done in Bash:
    Code:
    #/usr/bin/bash
    #These are the lyrics to the rhyme "99 Bottles of Beer on the wall, coding 
    #done in bash
    echo 99 bottles of beer on the wall, 99 bottles of beer.
    echo Take one down and pass it around, 98 bottles of beer on the wall.
    sleep 4
    echo 98 bottles of beer on the wall, 98 bottles of beer.
    echo Take one down and pass it around, 97 bottles of beer on the wall.
    sleep 4
    echo 97 bottles of beer on the wall, 97 bottles of beer.
    echo Take one down and pass it around, 96 bottles of beer on the wall.
    sleep 4
    echo 96 bottles of beer on the wall, 96 bottles of beer.
    echo Take one down and pass it around, 95 bottles of beer on the wall.
    sleep 4
    echo 95 bottles of beer on the wall, 95 bottles of beer.
    echo Take one down and pass it around, 94 bottles of beer on the wall.
    sleep 4
    echo 94 bottles of beer on the wall, 94 bottles of beer.
    echo Take one down and pass it around, 93 bottles of beer on the wall.
    sleep 4
    echo 93 bottles of beer on the wall, 93 bottles of beer.
    echo Take one down and pass it around, 92 bottles of beer on the wall.
    sleep 4
    echo 92 bottles of beer on the wall, 92 bottles of beer.
    echo Take one down and pass it around, 91 bottles of beer on the wall.
    sleep 4
    echo 91 bottles of beer on the wall, 91 bottles of beer.
    echo Take one down and pass it around, 90 bottles of beer on the wall.
    sleep 4
    echo 90 bottles of beer on the wall, 90 bottles of beer.
    echo Take one down and pass it around, 89 bottles of beer on the wall.
    sleep 4
    echo 89 bottles of beer on the wall, 89 bottles of beer.
    echo Take one down and pass it around, 88 bottles of beer on the wall.
    sleep 4
    echo 88 bottles of beer on the wall, 88 bottles of beer.
    echo Take one down and pass it around, 87 bottles of beer on the wall.
    sleep 4
    echo 87 bottles of beer on the wall, 87 bottles of beer.
    echo Take one down and pass it around, 86 bottles of beer on the wall.
    sleep 4
    echo 86 bottles of beer on the wall, 86 bottles of beer.
    echo Take one down and pass it around, 85 bottles of beer on the wall.
    sleep 4
    echo 85 bottles of beer on the wall, 85 bottles of beer.
    echo Take one down and pass it around, 84 bottles of beer on the wall.
    sleep 4
    echo 84 bottles of beer on the wall, 84 bottles of beer.
    echo Take one down and pass it around, 83 bottles of beer on the wall.
    sleep 4
    echo 83 bottles of beer on the wall, 83 bottles of beer.
    echo Take one down and pass it around, 82 bottles of beer on the wall.
    sleep 4
    echo 82 bottles of beer on the wall, 82 bottles of beer.
    echo Take one down and pass it around, 81 bottles of beer on the wall.
    sleep 4
    echo 81 bottles of beer on the wall, 81 bottles of beer.
    echo Take one down and pass it around, 80 bottles of beer on the wall.
    sleep 4
    echo 80 bottles of beer on the wall, 80 bottles of beer.
    echo Take one down and pass it around, 79 bottles of beer on the wall.
    sleep 4
    echo 79 bottles of beer on the wall, 79 bottles of beer.
    echo Take one down and pass it around, 78 bottles of beer on the wall.
    sleep 4
    echo 78 bottles of beer on the wall, 78 bottles of beer.
    echo Take one down and pass it around, 77 bottles of beer on the wall.
    sleep 4
    echo 77 bottles of beer on the wall, 77 bottles of beer.
    echo Take one down and pass it around, 76 bottles of beer on the wall.
    sleep 4
    echo 76 bottles of beer on the wall, 76 bottles of beer.
    echo Take one down and pass it around, 75 bottles of beer on the wall.
    sleep 4
    echo 75 bottles of beer on the wall, 75 bottles of beer.
    echo Take one down and pass it around, 74 bottles of beer on the wall.
    sleep 4
    echo 74 bottles of beer on the wall, 74 bottles of beer.
    echo Take one down and pass it around, 73 bottles of beer on the wall.
    sleep 4
    echo 73 bottles of beer on the wall, 73 bottles of beer.
    echo Take one down and pass it around, 72 bottles of beer on the wall.
    sleep 4
    echo 72 bottles of beer on the wall, 72 bottles of beer.
    echo Take one down and pass it around, 71 bottles of beer on the wall.
    sleep 4
    echo 71 bottles of beer on the wall, 71 bottles of beer.
    echo Take one down and pass it around, 70 bottles of beer on the wall.
    sleep 4
    echo 70 bottles of beer on the wall, 70 bottles of beer.
    echo Take one down and pass it around, 69 bottles of beer on the wall.
    sleep 4
    echo 69 bottles of beer on the wall, 69 bottles of beer.
    echo Take one down and pass it around, 68 bottles of beer on the wall.
    sleep 4
    echo 68 bottles of beer on the wall, 68 bottles of beer.
    echo Take one down and pass it around, 67 bottles of beer on the wall.
    sleep 4
    echo 67 bottles of beer on the wall, 67 bottles of beer.
    echo Take one down and pass it around, 66 bottles of beer on the wall.
    sleep 4
    echo 66 bottles of beer on the wall, 66 bottles of beer.
    echo Take one down and pass it around, 65 bottles of beer on the wall.
    sleep 4
    echo 65 bottles of beer on the wall, 65 bottles of beer.
    echo Take one down and pass it around, 64 bottles of beer on the wall.
    sleep 4
    echo 64 bottles of beer on the wall, 64 bottles of beer.
    echo Take one down and pass it around, 63 bottles of beer on the wall.
    sleep 4
    echo 63 bottles of beer on the wall, 63 bottles of beer.
    echo Take one down and pass it around, 62 bottles of beer on the wall.
    sleep 4
    echo 62 bottles of beer on the wall, 62 bottles of beer.
    echo Take one down and pass it around, 61 bottles of beer on the wall.
    sleep 4
    echo 61 bottles of beer on the wall, 61 bottles of beer.
    echo Take one down and pass it around, 60 bottles of beer on the wall.
    sleep 4
    echo 60 bottles of beer on the wall, 60 bottles of beer.
    echo Take one down and pass it around, 59 bottles of beer on the wall.
    sleep 4
    echo 59 bottles of beer on the wall, 59 bottles of beer.
    echo Take one down and pass it around, 58 bottles of beer on the wall.
    sleep 4
    echo 58 bottles of beer on the wall, 58 bottles of beer.
    echo Take one down and pass it around, 57 bottles of beer on the wall.
    sleep 4
    echo 57 bottles of beer on the wall, 57 bottles of beer.
    echo Take one down and pass it around, 56 bottles of beer on the wall.
    sleep 4
    echo 56 bottles of beer on the wall, 56 bottles of beer.
    echo Take one down and pass it around, 55 bottles of beer on the wall.
    sleep 4
    echo 55 bottles of beer on the wall, 55 bottles of beer.
    echo Take one down and pass it around, 54 bottles of beer on the wall.
    sleep 4
    echo 54 bottles of beer on the wall, 54 bottles of beer.
    echo Take one down and pass it around, 53 bottles of beer on the wall.
    sleep 4
    echo 53 bottles of beer on the wall, 53 bottles of beer.
    echo Take one down and pass it around, 52 bottles of beer on the wall.
    sleep 4
    echo 52 bottles of beer on the wall, 52 bottles of beer.
    echo Take one down and pass it around, 51 bottles of beer on the wall.
    sleep 4
    echo 51 bottles of beer on the wall, 51 bottles of beer.
    echo Take one down and pass it around, 50 bottles of beer on the wall.
    sleep 4
    echo 50 bottles of beer on the wall, 50 bottles of beer.
    echo Take one down and pass it around, 49 bottles of beer on the wall.
    sleep 4
    echo 49 bottles of beer on the wall, 49 bottles of beer.
    echo Take one down and pass it around, 48 bottles of beer on the wall.
    sleep 4
    echo 48 bottles of beer on the wall, 48 bottles of beer.
    echo Take one down and pass it around, 47 bottles of beer on the wall.
    sleep 4
    echo 47 bottles of beer on the wall, 47 bottles of beer.
    echo Take one down and pass it around, 46 bottles of beer on the wall.
    sleep 4
    echo 46 bottles of beer on the wall, 46 bottles of beer.
    echo Take one down and pass it around, 45 bottles of beer on the wall.
    sleep 4
    echo 45 bottles of beer on the wall, 45 bottles of beer.
    echo Take one down and pass it around, 44 bottles of beer on the wall.
    sleep 4
    echo 44 bottles of beer on the wall, 44 bottles of beer.
    echo Take one down and pass it around, 43 bottles of beer on the wall.
    sleep 4
    echo 43 bottles of beer on the wall, 43 bottles of beer.
    echo Take one down and pass it around, 42 bottles of beer on the wall.
    sleep 4
    echo 42 bottles of beer on the wall, 42 bottles of beer.
    echo Take one down and pass it around, 41 bottles of beer on the wall.
    sleep 4
    echo 41 bottles of beer on the wall, 41 bottles of beer.
    echo Take one down and pass it around, 40 bottles of beer on the wall.
    sleep 4
    echo 40 bottles of beer on the wall, 40 bottles of beer.
    echo Take one down and pass it around, 39 bottles of beer on the wall.
    sleep 4
    echo 39 bottles of beer on the wall, 39 bottles of beer.
    echo Take one down and pass it around, 38 bottles of beer on the wall.
    sleep 4
    echo 38 bottles of beer on the wall, 38 bottles of beer.
    echo Take one down and pass it around, 37 bottles of beer on the wall.
    sleep 4
    echo 37 bottles of beer on the wall, 37 bottles of beer.
    echo Take one down and pass it around, 36 bottles of beer on the wall.
    sleep 4
    echo 36 bottles of beer on the wall, 36 bottles of beer.
    echo Take one down and pass it around, 35 bottles of beer on the wall.
    sleep 4
    echo 35 bottles of beer on the wall, 35 bottles of beer.
    echo Take one down and pass it around, 34 bottles of beer on the wall.
    sleep 4
    echo 34 bottles of beer on the wall, 34 bottles of beer.
    echo Take one down and pass it around, 33 bottles of beer on the wall.
    sleep 4
    echo 33 bottles of beer on the wall, 33 bottles of beer.
    echo Take one down and pass it around, 32 bottles of beer on the wall.
    sleep 4
    echo 32 bottles of beer on the wall, 32 bottles of beer.
    echo Take one down and pass it around, 31 bottles of beer on the wall.
    sleep 4
    echo 31 bottles of beer on the wall, 31 bottles of beer.
    echo Take one down and pass it around, 30 bottles of beer on the wall.
    sleep 4
    echo 30 bottles of beer on the wall, 30 bottles of beer.
    echo Take one down and pass it around, 29 bottles of beer on the wall.
    sleep 4
    echo 29 bottles of beer on the wall, 29 bottles of beer.
    echo Take one down and pass it around, 28 bottles of beer on the wall.
    sleep 4
    echo 28 bottles of beer on the wall, 28 bottles of beer.
    echo Take one down and pass it around, 27 bottles of beer on the wall.
    sleep 4
    echo 27 bottles of beer on the wall, 27 bottles of beer.
    echo Take one down and pass it around, 26 bottles of beer on the wall.
    sleep 4
    echo 26 bottles of beer on the wall, 26 bottles of beer.
    echo Take one down and pass it around, 25 bottles of beer on the wall.
    sleep 4
    echo 25 bottles of beer on the wall, 25 bottles of beer.
    echo Take one down and pass it around, 24 bottles of beer on the wall.
    sleep 4
    echo 24 bottles of beer on the wall, 24 bottles of beer.
    echo Take one down and pass it around, 23 bottles of beer on the wall.
    sleep 4
    echo 23 bottles of beer on the wall, 23 bottles of beer.
    echo Take one down and pass it around, 22 bottles of beer on the wall.
    sleep 4
    echo 22 bottles of beer on the wall, 22 bottles of beer.
    echo Take one down and pass it around, 21 bottles of beer on the wall.
    sleep 4
    echo 21 bottles of beer on the wall, 21 bottles of beer.
    echo Take one down and pass it around, 20 bottles of beer on the wall.
    sleep 4
    echo 20 bottles of beer on the wall, 20 bottles of beer.
    echo Take one down and pass it around, 19 bottles of beer on the wall.
    sleep 4
    echo 19 bottles of beer on the wall, 19 bottles of beer.
    echo Take one down and pass it around, 18 bottles of beer on the wall.
    sleep 4
    echo 18 bottles of beer on the wall, 18 bottles of beer.
    echo Take one down and pass it around, 17 bottles of beer on the wall.
    sleep 4
    echo 17 bottles of beer on the wall, 17 bottles of beer.
    echo Take one down and pass it around, 16 bottles of beer on the wall.
    sleep 4
    echo 16 bottles of beer on the wall, 16 bottles of beer.
    echo Take one down and pass it around, 15 bottles of beer on the wall.
    sleep 4
    echo 15 bottles of beer on the wall, 15 bottles of beer.
    echo Take one down and pass it around, 14 bottles of beer on the wall.
    sleep 4
    echo 14 bottles of beer on the wall, 14 bottles of beer.
    echo Take one down and pass it around, 13 bottles of beer on the wall.
    sleep 4
    echo 13 bottles of beer on the wall, 13 bottles of beer.
    echo Take one down and pass it around, 12 bottles of beer on the wall.
    sleep 4
    echo 12 bottles of beer on the wall, 12 bottles of beer.
    echo Take one down and pass it around, 11 bottles of beer on the wall.
    sleep 4
    echo 11 bottles of beer on the wall, 11 bottles of beer.
    echo Take one down and pass it around, 10 bottles of beer on the wall.
    sleep 4
    echo 10 bottles of beer on the wall, 10 bottles of beer.
    echo Take one down and pass it around, 9 bottles of beer on the wall.
    sleep 4
    echo 9 bottles of beer on the wall, 9 bottles of beer.
    echo Take one down and pass it around, 8 bottles of beer on the wall.
    sleep 4
    echo 8 bottles of beer on the wall, 8 bottles of beer.
    echo Take one down and pass it around, 7 bottles of beer on the wall.
    sleep 4
    echo 7 bottles of beer on the wall, 7 bottles of beer.
    echo Take one down and pass it around, 6 bottles of beer on the wall.
    sleep 4
    echo 6 bottles of beer on the wall, 6 bottles of beer.
    echo Take one down and pass it around, 5 bottles of beer on the wall.
    sleep 4
    echo 5 bottles of beer on the wall, 5 bottles of beer.
    echo Take one down and pass it around, 4 bottles of beer on the wall.
    sleep 4
    echo 4 bottles of beer on the wall, 4 bottles of beer.
    echo Take one down and pass it around, 3 bottles of beer on the wall.
    sleep 4
    echo 3 bottles of beer on the wall, 3 bottles of beer.
    echo Take one down and pass it around, 2 bottles of beer on the wall.
    sleep 4
    echo 2 bottles of beer on the wall, 2 bottles of beer.
    echo Take one down and pass it around, 1 bottle of beer on the wall.
    sleep 4
    echo 1 bottle of beer on the wall, 1 bottle of beer.
    echo Take one down and pass it around, no more bottles of beer on the wall.
    sleep 3
    echo No beer, go buy more!
    echo Add the beer to the wall, 99 bottles of beer on the wall.
    And i didnt copy from the website, if you are wondering that.
    and if its not 99 but 9999, are you going to type that many echoes? Use functions, mathematics in bash for the tasks. Read the bash link in my sig for more bash.

  6. #56
    Join Date
    Nov 2007
    Location
    Georgia, United States
    Beans
    465
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by OutOfReach View Post
    Here's mine, remember that I'm just learning Python so don't eat me if I'm doing this all wrong .
    Code:
    #!/usr/bin/env python
    
    
    lineOne = "%i bottles of beer on the wall, %i bottles of beer."
    lineTwo = "Take one down and pass it around, %i bottles of beer on the wall.\n\n"
    numberOfBeers = 99
    
    while numberOfBeers >= 0:
    
        print lineOne % (numberOfBeers, numberOfBeers)
        print lineTwo % int(numberOfBeers - 1)
        numberOfBeers -= 1
    
        #In the next three blocks, we change the output so the ending of the song makes sense.
    
        if numberOfBeers == 2:
    
            print lineOne % (numberOfBeers, numberOfBeers)
            print "Take one down and pass it around, %i bottle of beer on the wall.\n\n" % int(numberOfBeers - 1)
            numberOfBeers -= 1
    
        if numberOfBeers == 1:
    
            print "%i bottle of beer on the wall, %i bottle of beer." % (numberOfBeers, numberOfBeers)
            print "Take one down and pass it around, no more bottles of beer on the wall.\n\n"
            numberOfBeers = 0
    
        if numberOfBeers == 0:
    
            print "No more bottles of beer on the wall, no more bottles of beer."
            print "Go to the store and buy some more, 99 bottles of beer on the wall.\n\n"
            #Takes us out of the while loop
            break
    I eat you :b. I am actually learning python myself, dont have enough knowledge to make anything workable tho.
    Ubuntu Beginners Team - Development Focus Group Leader
    Ubuntu Georgia Local Team - Website Administrator
    Ubuntu Forums Unanswered Posts Team - Leader

  7. #57
    Join Date
    Jun 2008
    Location
    California, USA
    Beans
    1,030
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 1

    Don't eat me!! D:

    All you need is hope to make things work.

    Blog | I'm available for programming contributions. C & Python.
    Intel Core i7 920 | EVGA x58 SLI | NVidia GeForce 8600 GT | WD 500GB HDD | Corsair XMS3 3GB | Ubuntu 9.04

  8. #58
    Join Date
    Aug 2007
    Location
    Novocastria, Australia
    Beans
    754
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 1

    Writtin in C++ (which seems to be a bad choice for this challenge, Python is much better suited to this kind of thing). I chose C++ because it is my newest language (only been learning properly for the last 2 weeks). PHP tags used for limited syntax highlighting.

    PHP Code:
    //Written by Peter Stace
    //Last modification Sat 2nd of August 2008

    #include <iostream>
    #include <string>
    #include <assert.h>
    using namespace std;

    // Outputs the number of bottles and then the word
    // bottles either plural or singular.
    //
    // Preconditions: numBottles is the current number of bottles on the wall. It
    //                should be a positive integer.
    // Postconditions: a message is printed to standard output.
    void bottles(int numBottles) {

        
    assert (numBottles >= 0); //numBottles should not be negative
        
        
    if (numBottles >= 2) {
            
    cout << numBottles << " bottles";
        } else if (
    numBottles == 1) {
            
    cout << "1 bottle";
        } else {
            
    cout << "no bottles";
        }
        
    }

    //the mainline of the programme
    int main() {

        for (
    int i 99>= 1i--) {
        
            
    //first line
            
    bottles(i);
            
    cout << " of beer on the wall, ";
            
    bottles(i);
            
    cout << " of beer." << endl;
            
            
    //second line
            
    cout << "Take one down and pass it around," << endl;
            
            
    //third line
            
    bottles(1);
            
    cout << " of beer on the wall.\n" <<endl;
        }
        
        
    //displayed at the end of the song
        
    cout << "Go to the store, buy some more," << endl;
        
    cout << "99 bottles of beer on the wall.\n" << endl;


  9. #59
    Join Date
    Nov 2007
    Location
    Georgia, United States
    Beans
    465
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [Beginner] Programming Challenge: 1

    Quote Originally Posted by OutOfReach View Post
    Don't eat me!! D:

    All you need is hope to make things work.
    You script works great . But i am still going to eat you .
    Ubuntu Beginners Team - Development Focus Group Leader
    Ubuntu Georgia Local Team - Website Administrator
    Ubuntu Forums Unanswered Posts Team - Leader

  10. #60
    Join Date
    Jul 2008
    Location
    cairo,egypt
    Beans
    107

    Re: [Beginner] Programming Challenge: 1

    Code:
    //using java
    //i think its pretty easy to understand the code so i didnt add any comments
    public class Lyrics {
    public static void main(String[]args)
    {
    	for(int bottles=99;bottles>0;bottles--)
    	{
    		if(bottles==2)
    		{
    		System.out.println(bottles+" bottles of beer on the wall, "+bottles+" bottles of beer");
    		System.out.println("Take one down and pass it around, "+(bottles-1)+" bottle of beer on the wall");
    		}
    		if(bottles==1)
    		{
    		System.out.println(bottles+" bottle of beer on the wall, "+bottles+" bottle of beer");
    		System.out.println("Take one down and pass it around, no more bottles of beer on the wall");
    		}
    		if(bottles>=3)
    		{
    		System.out.println(bottles+" bottles of beer on the wall, "+bottles+" bottles of beer");
    		System.out.println("Take one down and pass it around, "+(bottles-1)+" bottles of beer on the wall");
    		}
    	}
    	    System.out.println("No more bottles of beer on the wall, no more bottles of beer");
    	    System.out.println("Go to the store and buy some more, 99 bottles of beer on the wall");
    }
    }
    Last edited by mosty friedman; August 2nd, 2008 at 09:28 AM.

Page 6 of 27 FirstFirst ... 4567816 ... 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
  •