I'm having trouble with my programs for class.

Program 1

Write a function that receives a list as its parameter and returns a list with the length of each element. In the main function print the returned list.

def elementLength(list):
    list = raw_input("enter list")

    return len(list)

print elementLength(list)

What it does now is print the amount of characters. I think I know how to find the amount of characters in a word of a list but not one inputted by the user.

program 2:


Write a function that receives three strings
and prints them in order from lowest to highest.

def strings(raw_input)

      strings = raw_input("Enter strings")

      import string

      return strings(raw_input)

print string.uppercase(raw_input)
print string.lowercase(raw_input)
print string.digits(raw_input)

I've changed up this program a lot and the way it is now is pretty bad.


Thank you.

Okay, start simple and understand what raw_input and input actually do:

raw_input([prompt])ΒΆ

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:

>>> s = raw_input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"

If the readline module was loaded, then raw_input() will use it to provide elaborate line editing and history features.

Then understand lists:
http://docs.python.org/tutorial/datastructures.html

And then have another go at the problem, if you have any specific questions feel free to ask. But first try learn a bit more about what things do.

On problem #1 you are a little messed up. You need to send a list of elements to the your function that contains elements that the len() function can be applied to, like strings for instance. Then you return a list of these lengths.
BTW, do not use 'list' as a variable name.

Since you are talking about the length of strings, I assume that problem #2 asks you to return the list of strings in the order of length. So a list like
mylist =
would be:
mylist = [ 'of', 'list', 'strings']
or:
mylist =

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.