943,733 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1484
  • Python RSS
Dec 1st, 2008
0

Python-Tuple Help!

Expand Post »
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!
Similar Threads
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
StarZ is offline Offline
85 posts
since Dec 2008
Dec 1st, 2008
0

Re: Python-Tuple Help!

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?
Reputation Points: 94
Solved Threads: 48
Posting Whiz
BearofNH is offline Offline
321 posts
since May 2007
Dec 1st, 2008
0

Re: Python-Tuple Help!

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....
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
StarZ is offline Offline
85 posts
since Dec 2008
Dec 2nd, 2008
0

Re: Python-Tuple Help!

Hi,
I think its very simple.
I will give you rough idea about it.

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

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

Quote ...
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.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
rmansuri is offline Offline
3 posts
since Jan 2008
Dec 2nd, 2008
0

Re: Python-Tuple Help!

python Syntax (Toggle Plain Text)
  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
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Dec 2nd, 2008
0

Re: Python-Tuple Help!

Click to Expand / Collapse  Quote originally posted by BearofNH ...
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?
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
StarZ is offline Offline
85 posts
since Dec 2008
Dec 2nd, 2008
1

Re: Python-Tuple Help!

Click to Expand / Collapse  Quote originally posted by StarZ ...
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.
Reputation Points: 94
Solved Threads: 48
Posting Whiz
BearofNH is offline Offline
321 posts
since May 2007
Dec 3rd, 2008
0

Re: Python-Tuple Help!

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.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Dec 4th, 2008
0

Re: Python-Tuple Help!

Click to Expand / Collapse  Quote originally posted by BearofNH ...
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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: counting pixels in an image(ocr)
Next Thread in Python Forum Timeline: Play Sounds at different Speeds





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC