Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,917 members, 7,817,690 topics. Date: Saturday, 04 May 2024 at 05:23 PM

Pls Help With Python Problem - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Pls Help With Python Problem (6863 Views)

I Need HELP With This Python Problem / Build A Bare Bones Reddit Clone With Python And Flask (hands On Tutorial Thread) / Help With This Python Problem (2) (3) (4)

(1) (2) (3) (4) (Reply) (Go Down)

Re: Pls Help With Python Problem by bright007(f): 6:26pm On Jul 27, 2013
here is the data:
set1= ('20','30','21','14')
set2= ('66','04','90','13')
set3= ('38','63','45','11')
set4= ('20','30','44','60')
set5= ('31','11','90','60')
set6= ('27','38','30','36')
## the data can contain thousands of sets with each set having just 4 different numbers in the range(90)###
how do i create a program using python that searches for a specified number or any number in the data above based on "properties" of the number in the data.
properties refers to how a particular number occurs from one set to another.the program searches data for any number with d property inputed by d user and returns the number and the sets where the number has the properties or else it returns "property not available"
for example 20 and 30 occurs in set1 at position 0 and 1 respectively and re_occurs at set4 position 0 and 1 respectively.
Re: Pls Help With Python Problem by Nobody: 6:35pm On Jul 27, 2013
Ok. If I understand, u want to be able to input a number and search for how many times it occurs in a collection of sets, which sets it occurs in and its position (index) in the respective set.
Re: Pls Help With Python Problem by bright007(f): 6:56pm On Jul 27, 2013
assuming a user is searching for any number in the data which occurs in any set at position 0 #position is optional# which re-occurs at position 0 after counting 4 sets #counting is a property#...the program searches and returns 20(the number),set1(the set where it occurs), set4 (the set where it re-occurs after counting 4 sets)...if position is not specified,the program returns 20 and 30,set1,set4 (the 2 numbers that has the property specified # i.e the numbers that re-occurs after counting 4 sets# ) but let say the user searches for any number that occurs in any set at position 3 #position specified# which re-occurs at 1 #position specified again# after counting for sets...the program returns "not found or not available".
this is because although 20 and 30 occurs in set1,they are not in position 3 and even if any of them were to occur at position 3,both numbers are not in position 1 after counting 4 sets as specified by the user.
Re: Pls Help With Python Problem by bright007(f): 7:13pm On Jul 27, 2013
PhenomenonVFX: Ok. If I understand, u want to be able to input a number and search for how many times it occurs in a collection of sets, which sets it occurs in and its position (index) in the respective set.
..yeah,thats close.
let me make it simply.lets call the function "jump".in the data above,the number 20 and 30 occurs in set1 and and also at set4.simply put,the numbers are said to have jumped from set1 to set4.they jumped 2 sets # set2 and set3 # and re-occurs at set4.
the problem now is,the user is searching a number #number can be specified by user or not# which occur anywhere in the which "jumps" by a specified count #this must be specified by user# to another set.
all the program does after searching is to return d number that meets the search conditions,the set where occur,and the set where they have jumped to # if the number is not specified,all numbers that meet this search condition are returned#
##let me leave the position a number occupies out of it##
Re: Pls Help With Python Problem by Nobody: 8:42pm On Jul 27, 2013
Hmmm.
Still not clear. But getting clearer. Let me see if I understand.
The function should take two set's number and try to figure out if a number with a certain property occurs in the two sets?
One question though, what type would d property be? Would it be an integer or a sentence? How would the property be specified? Would the property always be d same or would it change? I am not even sure I understand the problem any longer. grin
I am guessing u are making up this problem off of the top of ur head hence the difficulty in relating it to me in technical terms.
Do me a favour; tell me what the inputs are in very short sentences.
Re: Pls Help With Python Problem by bright007(f): 9:19pm On Jul 27, 2013
PhenomenonVF:
One question though, what type would d property be? Would it be an integer or a sentence? How would the property be specified? Would the property always be d same or would it change? I am not even sure I understand the problem any longer. grin
I am guessing u are making up this problem off of the top of ur head hence the difficulty in relating it to me in technical terms.
Do me a favour; tell me what the inputs are in very short sentences.
sorry for not being concise ##my brain is about to knock##
the type would always be an integer,since the data is composed of integers.
def jump(x) in any set that re-occurs after skippin (N number of set)
#where x=any int in the data which the user inputs.
N = this refers to the number of sets skipped by x before occurring again.the user must input N also.
if there is a number(x) in the data which occurs and re-occurs again after skipping N sets,the program returns the number,the set it first occurs and d set where it re-occurs.
Re: Pls Help With Python Problem by bright007(f): 9:57pm On Jul 27, 2013
to make it clearer,look at the number 12 in the data below.
set1=('12','18','44','56')
set2=('13','40','16','04')
set3=('63','85','78','60')
set4=('17','35','12','20')
set5=('32','41','73','87')
set6=('12','23','02','61')
the number 12 occurs at set1 (position 0),set4(position 2), and set6(position 0).
if the user inputs:
search(x) which re-occurs after (2) sets.
the program returns the number 12,set1, and set4. in this example x=12, and N=2.
N equals 2 because the number 12 skips set2 and set3 before re-occuring at set4.
but if the user inputs:
search(x) which re-occurs after (4)sets.
the program returns the number 12,set1, and set6.
it returns 12 because,it is d only number in the dat which after occuring,re-occurs again after skipping 4 sets #hence satisfying N=4#
Hence anytime the value of N changes, the number returned will be different .thanks for your time.
Re: Pls Help With Python Problem by funkymeky: 11:12pm On Jul 27, 2013
Pls I nid ur help.... I'm new to python pls I want to know if the programin lang nids a compiler and an interpreter... Pls if it does can I have d link to download them..thanks a lot house
Re: Pls Help With Python Problem by Nobody: 3:58am On Jul 28, 2013
Aha. I think I get it now. Clearer. cheesy. I will get back to u later in the day.
Re: Pls Help With Python Problem by Nobody: 3:59am On Jul 28, 2013
funkymeky: Pls I nid ur help.... I'm new to python pls I want to know if the programin lang nids a compiler and an interpreter... Pls if it does can I have d link to download them..thanks a lot house

Python uses an interpreter.
U can check www.python.org
Re: Pls Help With Python Problem by bright007(f): 6:23am On Jul 28, 2013
PhenomenonVFX: Aha. I think I get it now. Clearer. cheesy. I will get back to u later in the day.
ok..thanks
Re: Pls Help With Python Problem by Nobody: 1:36pm On Jul 28, 2013
This is one long code. It is getting hard for me to type it on a mobile and keep track of what I am doing. I will have to do this on a text editor. Notepad++ will do just fine. I will write the code when I am on my computer later today, save it as a Python (.py) file and probably attach it to a post on this thread. Hope that will be okay for u?
Re: Pls Help With Python Problem by Nobody: 2:04pm On Jul 28, 2013
Also to be sure I am coding the solution to the right problem, let's do a review.

1. U want a function that takes three inputs: x; a number in a set, N; the number of sets x jumps before reoccuring, p; the position of number must occupy in the sets.

2. The parameters N and p are optional.

3. If N and p are specified, the function prints x if it reoccurs in more than one set N sets appart and at position p. And also prints the sets in which that condition is satisfied.

4. Whenever p is unspecified, any set in which x occurs after jumping N sets should be printed.

5. Whenever N is unspecified, any set in which x occurs at position p is printed.

6. Whenever both N and p are unspecified, any set in which x occurs should be printed.
Re: Pls Help With Python Problem by bright007(f): 5:07pm On Jul 28, 2013
thanks boss...let me answer d kwessions:
(1)the function takes 3 inputs.
(a) x is any number in the data.x may or may not be specified.if not specified,any number in any set that satisfies the next argument #argument N and P# is returned.
(b)P is optional but N is not.
(c)correct,N is the number of sets the number x MUST skip before re-occuring.
(2)N is not optional.N must be specified,N determines which number is returned when x is not specified as well as the set to be returned #set where x re-occurs after N sets #
(3)you are correct except that N MUST be specified because anytime the value of N changes, x also changes.
(4)the set where x re-occurs must always be returned regardless of whether p is specified or not.
(5)N must be specified
# i think this answers the above question.
notesad1)from the data above,there are only 5 possible positions in every set(from 0-4).
(2)the number of sets runs to thousands hence the data very large but X ranges from 1 to 90.the numbers repeat randomly
Re: Pls Help With Python Problem by bright007(f): 5:57pm On Jul 28, 2013
also
(1)if x is not specified and p is not specified,the program returns any number that satisfies the argument N as well as the set where the number re-occurs.else it returns "not available"
(2)if x and p are specified,the program will not return x #since it's already specified# but will return the set where x re-occurs .
(3)if x is specified and p is not, the program returns the set where x has re-occured ## N is a condition that must be met.
else it returns "not available"
(4)generally,if any argument is specified,it becomes obligatory for the program to return the results that satisfies the condition,else it returns"not available"
Re: Pls Help With Python Problem by bright007(f): 9:02pm On Jul 28, 2013
@pheno:just checked if you have posted the code.if you dont still get it let me know.
Re: Pls Help With Python Problem by Nobody: 6:14pm On Jul 29, 2013
OP. I am thru with ur code. It is just remaining to make it cleaner and more readable for u and to add a lot of comments that tries to explain stuff. I will finish that once I am free later tonite so u should see the code by 2moro. It is a lenghty code, I must warn ya. And as much as I have tried to make it simple, u would need a good understanding of Python's data structures like tuples and lists to grasp it totally. cheesy Cheers.
Re: Pls Help With Python Problem by saddler: 8:28pm On Jul 29, 2013
@ phenovfx..do you know any computer school in lagos that are good in python?
Re: Pls Help With Python Problem by bright007(f): 8:54pm On Jul 29, 2013
PhenomenonVFX: OP. I am thru with ur code. It is just remaining to make it cleaner and more readable for u and to add a lot of comments that tries to explain stuff. I will finish that once I am free later tonite so u should see the code by 2moro. It is a lenghty code, I must warn ya. And as much as I have tried to make it simple, u would need a good understanding of Python's data structures like tuples and lists to grasp it totally. cheesy Cheers.
thanks boss...i am waiting patiently.
Re: Pls Help With Python Problem by Nobody: 9:49pm On Jul 30, 2013
Hi. Been busy. Just got the time to finish up ur code. It is the "set.py" file attached to this post. It is 200 lines. I took the liberty to add more sets just for testing sake. I endeavoured to make it as clear as possible. Like I said, u will be needing the knowledge of tuples to understand this one. And maybe some string formating.
Test the code in Python 2.6 or Python 2.7
Cheers. smiley

Re: Pls Help With Python Problem by Nobody: 11:05pm On Jul 30, 2013
saddler: @ phenovfx..do you know any computer school in lagos that are good in python?

I dont believe in computer schools. I am largely a self-taught person. Most of those schools just dump a lot of printed e-books on ur lap and quiz u on it after collecting a small fortune from u. The best way is to learn urself. At least, that is hw I see it.
Re: Pls Help With Python Problem by bright007(f): 2:10am On Jul 31, 2013
PhenomenonVFX: Hi. Been busy. Just got the time to finish up ur code. It is the "set.py" file attached to this post. It is 200 lines. I took the liberty to add more sets just for testing sake. I endeavoured to make it as clear as possible. Like I said, u will be needing the knowledge of tuples to understand this one. And maybe some string formating.
Test the code in Python 2.6 or Python 2.7
Cheers. smiley
...
the occur function was perfect,returning expected results.i must say you are a genus.
the occur2 function where you have to put in N and I (item) was not returning the two sets as the occur function was doing.pls tell me the adjustments to be made.
the run_occurs function where you have to input N,I, and P was always returning "the item 12 did not meet the search conditions at position X ##even after i exhausted all available positions for the number 12 which occured at position =0,after N=4.
pls help me with the necessary adjustments.
thank you very much for your kind gesture.
Re: Pls Help With Python Problem by Nobody: 7:53am On Jul 31, 2013
Funny enough, that part of the code was the only one that was working yesterday. The one u claimed is working had some bugs yesterday and I fixed it. Now the one that didnt give me problems isnt working? Imagine. smiley
Well, I will run the code again later in the day and see what is wrong. Later then
Re: Pls Help With Python Problem by bright007(f): 8:59am On Jul 31, 2013
PhenomenonVFX: Funny enough, that part of the code was the only one that was working yesterday. The one u claimed is working had some bugs yesterday and I fixed it. Now the one that didnt give me problems isnt working? Imagine. smiley
Well, I will run the code again later in the day and see what is wrong. Later then
ok...boss
also i want you to educate me on the use of the sign "%".I seem not to get what it means when studying the code.
Re: Pls Help With Python Problem by Nobody: 10:18am On Jul 31, 2013
The % sign is used for string formating. What is does is replace the corresponding string sign with the corresponding element in the replacement tuple.
For example:
name="John"
age=10
print("%s is %d years old" %(name, age))
The above prints:
John is 10 years old.

Note that the replacement tuple (name, age) holds two elements. And the formatting replaces %s with the value of name and replaces %d with the value of age.

Also note that name has a string for value and age has an integer value:
%s is replaced with a string
%d is replaced with an integer.
If u try replacing %s with anything other than something with a string value, u get an error.

Be advised that the number of % used in the string formatting must be equal to the number of elements in the replacement tuple else u get an error.

There are other countless formatting options in Python if I recall correctly. There is %f for floating-point numbers. There is %o for octal numbers.....etc.

There is also some form of advanced string formatting u can do with all of the above.
For instance,
amount= 123.459
item= "money"
print("The %s is about %.1f Naira" %(item, amount))
The above prints:
The money is about 123.4 Naira.

The %.1f tells the string formating to use only one decimal place of the floating point number that is substituted.

I hope that is clear now. Expect ur code later in the day.
Re: Pls Help With Python Problem by Nobody: 3:04pm On Jul 31, 2013
OP. I ran the code again and nothing seems to be wrong with it. To be sure, I made some ammendments to the code so that it is more clear than before. And I have attached it to this post.
The occur2 and run-occur functions are working alright. I tested 12 and 13 at with or without position 0 and they gave me the right results. Maybe u tampered with the code. Here is a new one.

Re: Pls Help With Python Problem by bright007(f): 6:07pm On Jul 31, 2013
thank you boss for the expert analysis.i will try the new code now.
Re: Pls Help With Python Problem by Nobody: 12:27pm On Aug 01, 2013
I hope the code is working well now.
Re: Pls Help With Python Problem by bright007(f): 7:46am On Aug 02, 2013
PhenomenonVFX: I hope the code is working well now.
..hi pheno!..i am on a short trip to lagos.i have downloaded the file but havnt run it cos i left my system at home.
When i get back,i will run it.
pls there is just one remaining question on this program i wanna ask.
but that will be when i am back.
Thank you a million times.
Re: Pls Help With Python Problem by bright007(f): 1:12am On Aug 07, 2013
@phenomenon:hello boss,i just came back yesterday from my trip.
i ran the modified run_occurs function.it was working but not returning the sets where the property occured.it was able to tell if the input satisfies conditions N, I , and P but when the input does,it does not return the sets where these conditions where satisfied.pls help me on this one.
Re: Pls Help With Python Problem by Nobody: 8:44am On Aug 07, 2013
I still dont see anything wrong with the code. It is working just fine here. The run-occurs function does not do what u say. It's job is just to call the other functions that do the thing u want by passing them d apt parameters. U arent supposed to pass anything to that function. The program does that.
That is why I am getting the feeling u tampered with the code.
U shouldnt be touching the run-occurs at all. If u run the code, the instructions there should suffice to do whatever u want. Run d code again and this time FOLLOW THE INSTRUCTIONS the running program gives u.
If u have tampered with the code in any way, let me know so I can send u another in pristine conditions or u could download the last one I sent and retry it.
Cheers. smiley
Re: Pls Help With Python Problem by bright007(f): 7:28pm On Aug 07, 2013
thanks boss,i have successfully ran the program and i had to modify my post to make it clearer.
i would like you to help me with these corrections:
(1)the current program supports the conditions below
(a)if number and position are specified
(b)if only number is specified
(c)if only N is specified
pls help me write for:
(a)if only position is specified.

(2)one limitation of this program is that it only return one result per number.sometimes there could be instances where there are up to many results per number.this modification should work for all conditions of the program.
(3)the condition of P (position) should be modified thus:
if P is specified,P (input) should only refer to the second set where a condition is met e.g
set1=12 13 14
set2=18 45 16
set3=17 12 54
set4=22 16 32
if i input P=1 and N=1,it should return set1,set3 for 12 and set2,set4 for 16 according to the data above.

(1) (2) (3) (4) (Reply)

Python Tutorial Group / Php/mysql Help:how To Run Sql Query From A Link / How Was Nairaland Able To Achieve Its Speed

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 70
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.