Python-Tuple Help!

Thread Solved

Join Date: Dec 2008
Posts: 65
Reputation: StarZ is an unknown quantity at this point 
Solved Threads: 1
StarZ StarZ is offline Offline
Junior Poster in Training

Python-Tuple Help!

 
0
  #1
Dec 1st, 2008
i have just been learning python(tuple) at school. And this is my first assignment. I can't seem to figure it out.

The assignment is on this website: http://schools.tdsb.on.ca/danforthcti/python/main.html
Go to lesson 8>scroll down>its called programming Assignment 9.

Can someone help me out? It's simple enough right? thank you!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 311
Reputation: BearofNH is on a distinguished road 
Solved Threads: 40
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz

Re: Python-Tuple Help!

 
0
  #2
Dec 1st, 2008
Yes, it's simple enough. The example given started out with mypocket = ("gum", "wallet", "old kleenex", "bus ticket") . Was there something unusual about this that prevented you from extending that from 4 items to 10?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 65
Reputation: StarZ is an unknown quantity at this point 
Solved Threads: 1
StarZ StarZ is offline Offline
Junior Poster in Training

Re: Python-Tuple Help!

 
0
  #3
Dec 1st, 2008
the assignment says to : "The program will then ask you how many items you want from the tuple, and then output them to you."
I don't know how to do that part....
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3
Reputation: rmansuri is an unknown quantity at this point 
Solved Threads: 2
rmansuri rmansuri is offline Offline
Newbie Poster

Re: Python-Tuple Help!

 
0
  #4
Dec 2nd, 2008
Hi,
I think its very simple.
I will give you rough idea about it.

first, use raw_input() for asking user to enter number.

number =raw_input('How many item you need ?')
define tuple.
like
my_tuple = range(1,10)
then use random library for random selection

import random
random.sample(my_tuple,number )
got no time to write proper program but this will help you out. let me know if you want me to write program.
Last edited by rmansuri; Dec 2nd, 2008 at 5:29 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Python-Tuple Help!

 
0
  #5
Dec 2nd, 2008
  1. mypocket = ("gum", "wallet", "old kleenex", "bus ticket")
  2. input_user = int (raw_input('How many item you need ? \n'))
  3. for i in range(input_user):
  4. print mypocket[i],
  5. #this will print from first to the limit of range
  6. #No catching of exceptions
  7. #use random module to randomize selection
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 65
Reputation: StarZ is an unknown quantity at this point 
Solved Threads: 1
StarZ StarZ is offline Offline
Junior Poster in Training

Re: Python-Tuple Help!

 
0
  #6
Dec 2nd, 2008
Originally Posted by BearofNH View Post
Yes, it's simple enough. The example given started out with mypocket = ("gum", "wallet", "old kleenex", "bus ticket") . Was there something unusual about this that prevented you from extending that from 4 items to 10?
I know how to do that part... obviously.
Theres 2 parts to that question.... >.>" did u not read it all?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 311
Reputation: BearofNH is on a distinguished road 
Solved Threads: 40
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz

Re: Python-Tuple Help!

 
1
  #7
Dec 2nd, 2008
Originally Posted by StarZ View Post
I know how to do that part... obviously.[...]
That doesn't square with what you said in the original post ... you know ... the part that reads "I can't seem to figure it out." For all I know, English isn't your native language. Just wanted to make sure we start out with common definitions.

Also it appears you have not read the homework assistance announcement. Generally what goes on here is you post what code you have written (following syntax highlighting guidelines) and lots of folks will be glad to help. But most folks (evidently not all) want you to show some effort first.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,008
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 285
woooee woooee is offline Offline
Veteran Poster

Re: Python-Tuple Help!

 
0
  #8
Dec 3rd, 2008
I've flagged this as a bad post. Since this is the first time, hopefully it was done correctly. This was the message:

This post is from someone who posted a link to their homework assignment, with no attempt to code anything themselves, and then asked for the answer. Further, they berate someone for not reading the homework assignment completely. Any one who is too lazy to cut and paste the question into the forum should not criticize someone else. We don't want to encourage the attitude of, "I'll sit here on the veranda in my rocking chair while you go fetch the homework from the web for me, and then code the answer while I sit here rocking away". Obviously, this violates the "only help those who shown some effort" and also violates the "keep it pleasant" guidline.
Last edited by woooee; Dec 3rd, 2008 at 6:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
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: 928
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python-Tuple Help!

 
0
  #9
Dec 4th, 2008
Originally Posted by BearofNH View Post
That doesn't square with what you said in the original post ... you know ... the part that reads "I can't seem to figure it out." For all I know, English isn't your native language. Just wanted to make sure we start out with common definitions.

Also it appears you have not read the homework assistance announcement. Generally what goes on here is you post what code you have written (following syntax highlighting guidelines) and lots of folks will be glad to help. But most folks (evidently not all) want you to show some effort first.
You are correct! If the OP will keep going with this attitude, I will give an infraction.
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