I require help with making 3 simple program/functions

Thread Solved

Join Date: Oct 2009
Posts: 4
Reputation: Judgment is an unknown quantity at this point 
Solved Threads: 0
Judgment Judgment is offline Offline
Newbie Poster

I require help with making 3 simple program/functions

 
-1
  #1
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]

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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 45
Reputation: Mathhax0r is an unknown quantity at this point 
Solved Threads: 9
Mathhax0r Mathhax0r is offline Offline
Light Poster
 
0
  #2
18 Days Ago
The first two only require one liners of logic, so here:

  1. n = int(raw_input("How many squares? "))
  2. squares = [x*x for x in range(1,n+1)]
  3. print square
  1. def even_only(argList):
  2. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: sfeldma3 is an unknown quantity at this point 
Solved Threads: 1
sfeldma3 sfeldma3 is offline Offline
Newbie Poster
 
0
  #3
18 Days Ago
Originally Posted by Judgment View Post
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.
Use the modular division operator on each number inside a loop. If the result of modular division is 0 then the number is even, if the result is 1 then the number is odd.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #4
18 Days Ago
Originally Posted by Mathhax0r View Post
The first two only require one liners of logic, so here:

  1. n = int(raw_input("How many squares? "))
  2. squares = [x*x for x in range(1,n+1)]
  3. print square
  1. def even_only(argList):
  2. 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.
For homework problems please give help in the form of hints, not total solutions or the OP will not learn anything.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC