| | |
I require help with making 3 simple program/functions
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 4
Reputation:
Solved Threads: 0
1. I need to make a program that creates a list that contains the first n perfect squares. All I know is that it starts with
n = int(raw_input("How many squares? "))
and ends with
print squares
An example of how this program should work is:
How many squares? 5
[1, 4, 9, 16, 25]
2. I need to create a function that takes a list as its only argument. It's needs to return a new list containing all (and only) the elements of 1 which are divisible by 2. The original list needs to remain the same.
Example of how this works is:
even_only([1, 3, 6, 10, 15, 21, 28]) should return
[6, 10, 28]
3. I need a function that translates a single English sentence into pig latin.
I honestly have no idea how to start any of these and any help would be greatly appreciated.
n = int(raw_input("How many squares? "))
and ends with
print squares
An example of how this program should work is:
How many squares? 5
[1, 4, 9, 16, 25]
2. I need to create a function that takes a list as its only argument. It's needs to return a new list containing all (and only) the elements of 1 which are divisible by 2. The original list needs to remain the same.
Example of how this works is:
even_only([1, 3, 6, 10, 15, 21, 28]) should return
[6, 10, 28]
3. I need a function that translates a single English sentence into pig latin.
I honestly have no idea how to start any of these and any help would be greatly appreciated.
•
•
Join Date: Aug 2009
Posts: 45
Reputation:
Solved Threads: 9
0
#2 18 Days Ago
The first two only require one liners of logic, so here:
As for the pig latin, you'll need to break the sentence down into words with split, do something to each word that will make it pig latin, then remake the sentence with join.
Python Syntax (Toggle Plain Text)
n = int(raw_input("How many squares? ")) squares = [x*x for x in range(1,n+1)] print square
Python Syntax (Toggle Plain Text)
def even_only(argList): return filter(lambda m: m%2==0, argList)
As for the pig latin, you'll need to break the sentence down into words with split, do something to each word that will make it pig latin, then remake the sentence with join.
Last edited by Mathhax0r; 18 Days Ago at 12:01 am.
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 1
0
#3 18 Days Ago
•
•
•
•
1. I need to make a program that creates a list that contains the first n perfect squares. All I know is that it starts with
n = int(raw_input("How many squares? "))
and ends with
print squares
An example of how this program should work is:
How many squares? 5
[1, 4, 9, 16, 25]
Create a loop structure that does n loops. Inside the loop, for each iteration, take the number of the iteration times itself and add it to a vector.
2. I need to create a function that takes a list as its only argument. It's needs to return a new list containing all (and only) the elements of 1 which are divisible by 2. The original list needs to remain the same.
Example of how this works is:
even_only([1, 3, 6, 10, 15, 21, 28]) should return
[6, 10, 28]
3. I need a function that translates a single English sentence into pig latin.
I honestly have no idea how to start any of these and any help would be greatly appreciated.
0
#4 18 Days Ago
•
•
•
•
The first two only require one liners of logic, so here:
Python Syntax (Toggle Plain Text)
n = int(raw_input("How many squares? ")) squares = [x*x for x in range(1,n+1)] print squarePython Syntax (Toggle Plain Text)
def even_only(argList): return filter(lambda m: m%2==0, argList)
As for the pig latin, you'll need to break the sentence down into words with split, do something to each word that will make it pig latin, then remake the sentence with join.
May 'the Google' be with you!
![]() |
Similar Threads
- Need help with making a simple program! (newbie) (C++)
- Help debugging a simple program. (Python)
- gcc header files and math libary (C++)
- Need advice & help with a very simple program (IT Professionals' Lounge)
- Making a simple sliding shooter. (VB.NET)
- Program help (C++)
- Erroneus outputs in string manipulation simple program (C++)
- I am a girl doing my 1st simple program (C)
Other Threads in the Python Forum
- Previous Thread: Need helping writing Prime number code
- Next Thread: several questions about Glade & pygtk
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






