This forum is in archive mode. You will not be able to post new content.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Sk33ter

Pages: [1]
1
Scripting Languages / Another python question.
« on: April 09, 2012, 10:03:18 PM »
As I said before, I am learning python and have come across yet another exercise that I can not quite complete.

This is what it says:
In this exercise you'll use an existing function, and while adding your own create a fully functional program.
 1. Add a function named list_benefits()- that returns the following list of strings: "More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"
 2. Add a function named build_sentence(info) which receives a single argument containing a string and returns a sentence starting with the given string and ending with the string " is a benefit of functions!"
 3. Run and see all the functions work together!


This is what they give you in the code box to start out with:
Code: [Select]
#Add your functions here (before the existing functions)

def name_the_benefits_of_functions():
    list_of_benefits = list_benefits()
    for benefit in list_of_benefits:
        print build_sentence(benefit)

name_the_benefits_of_functions()


This is what I have so far:
Code: [Select]
#Add your functions here (before the existing functions)
def list_benefits(a, b, c, d):
    return a, b, c, d
def name_the_benefits_of_functions():
    list_of_benefits = list_benefits("More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together")
    for benefit in list_of_benefits:
        def build_sentence(info):
            return list_benefits, "is a benefit of functions!"
        print build_sentence(benefit)


name_the_benefits_of_functions()


It runs, but this is the outcome:
Code: [Select]
(<function list_benefits at 0x17133e3cd09ecd08>, 'is a benefit of functions!')
(<function list_benefits at 0x17133e3cd09ecd08>, 'is a benefit of functions!')
(<function list_benefits at 0x17133e3cd09ecd08>, 'is a benefit of functions!')
(<function list_benefits at 0x17133e3cd09ecd08>, 'is a benefit of functions!')

2
Hacking and Security / Re: Language purposes
« on: April 09, 2012, 08:11:41 PM »
OK, if I knew a compiled language such as C++ would I be able to find exploits in other compiled languages?

3
Hacking and Security / Language purposes
« on: April 09, 2012, 07:46:33 PM »
Could someone tell me the purpose of all the main languages (python, C++, C, pearl, and I know I'm missing some so please fill in)

Thanks in advance.

4
Scripting Languages / Re: Coding Help
« on: April 03, 2012, 02:10:04 AM »
Thank you all for the help !  :D

Code: [Select]
numbers = [
    951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
    615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
    386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
    399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
    815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
    958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
    743, 527
]

# your code goes here
for i in numbers:
    if i == 412:
        break
    print i

5
Scripting Languages / Re: Coding Help
« on: April 02, 2012, 09:22:00 PM »
Ok so I got it, but it still prints out 412.

Code: [Select]
numbers = [
    951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
    615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
    386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
    399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
    815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
    958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
    743, 527
]

# your code goes here
for i in numbers:
    print i
    if i == 412:
        break

I need it so it does not print 412

Loop through and print out all even numbers from the numbers list in the same order they are received, but only up to the number "412" (not including it) Stop there and ignore all numbers past 412 in the sequence. (Note there will be numbers over 412.)

6
Scripting Languages / Re: Coding Help
« on: April 02, 2012, 04:17:00 AM »
OK I've tried everything but it keeps saying:

Traceback (most recent call last):
  File "/base/data/home/apps/s~learnpythonjail/1.354953192642593048/main.py", line 99, in post
    exec(cmd, safe_globals)
  File "<string>", line 14
     if equal to 412
               ^
 SyntaxError: invalid syntax

Code: [Select]
i = 0
for i in numbers:
    if equal to 412 break
    print i

also tried:

Code: [Select]
for i in numbers:
    if i == 412 break
    print numbers



7
Scripting Languages / Coding Help
« on: April 01, 2012, 06:48:29 PM »
I'm learning python and I'm on for and while loops. As i don't fully get for loops, I also can not figure out the answer to the exercise. The exercise is:

Loop through and print out all even numbers from the numbers list in the same order they are received, but only up to the number "412" (not including it) Stop there and ignore all numbers past 412 in the sequence. (Note there will be numbers over 412.)
Code: [Select]
numbers = [
    951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
    615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
    386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
    399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
    815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
    958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
    743, 527
]

# your code goes here




and that is the code they gave me so far.

So in short could someone clarify for loops and help me through the exercise (please don't just tell me the answer).

Thanks!

Pages: [1]


Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.