DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   Python-Tuple Help! (http://www.daniweb.com/forums/thread160336.html)

StarZ Dec 1st, 2008 7:49 pm
Python-Tuple Help!
 
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!

BearofNH Dec 1st, 2008 8:56 pm
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?

StarZ Dec 1st, 2008 9:20 pm
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....

rmansuri Dec 2nd, 2008 5:28 am
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.

evstevemd Dec 2nd, 2008 5:51 am
Re: Python-Tuple Help!
 
mypocket = ("gum", "wallet", "old kleenex", "bus ticket")
input_user = int (raw_input('How many item you need ? \n'))
for i in range(input_user):
    print mypocket[i],
    #this will print from first to the limit of range
    #No catching of exceptions
    #use random module to randomize selection

StarZ Dec 2nd, 2008 11:31 am
Re: Python-Tuple Help!
 
Quote:

Originally Posted by BearofNH (Post 748420)
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?

BearofNH Dec 2nd, 2008 8:58 pm
Re: Python-Tuple Help!
 
Quote:

Originally Posted by StarZ (Post 748842)
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.

woooee Dec 3rd, 2008 6:03 pm
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.

vegaseat Dec 4th, 2008 12:19 pm
Re: Python-Tuple Help!
 
Quote:

Originally Posted by BearofNH (Post 749071)
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.


All times are GMT -4. The time now is 9:36 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC