Silkroad Online Forums

A community forum for the free online game Silkroad Online. Discuss Silkroad Online, read up on guides, and build your character and skills.

Faq Search Members Chat  Register Profile Login

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Python
PostPosted: Fri Apr 08, 2011 5:37 pm 
Active Member
User avatar
Offline

Joined: May 2009
Posts: 730
Location: Yes.
Hey guys,

I could use a little help here if you are good at Python.

So, let's say I have a txt file in which I have the followin lines, let's name it input.txt

Computer
10000
20000
30000
Book
3000
2000
1000
Whatever
1
3
2

Now, the task is to write a script which creates a file and stores the highest bid in it with the corresponding item. So, it should look like this:

Computer 30000
Book 3000
Whatever 3


Yea, well, some idea would be nice, I'd appreciate it:) I have done some research but still haven't figured it out.

_________________
Phaedra


Top
 Profile  
 
 Post subject: Re: Python
PostPosted: Sat Apr 09, 2011 1:09 am 
Addicted Member
User avatar
Offline

Joined: Apr 2008
Posts: 2612
Location: Texas
I've never coded in python. Never even looked at it's syntax. What is it that you're having a problem with? The logic of the program or the syntax?

Loop through the file testing each line to see if it is a character string or integer.
If it's a character, keep looping through each line, testing it against the previous to see which is largest. Continue saving the largest until you see a character string, at this point you print out the string found originally + highest value and repeat the above process on the character string you just encountered...

I hope that makes a little sense. I'm in a rush, but I can write out the sudo-code later if ya want...

Think through the logic...perhaps draw a picture.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Python
PostPosted: Sat Apr 09, 2011 1:15 am 
Active Member
User avatar
Offline

Joined: Mar 2008
Posts: 770
Location:
Leagueoflegends
Assuming each item has only 3 bids:

open new file
while (file isn't at the end)
-read first block of chars
-for i=0 to i=2
--read bid
--convert to int
--place in static array
-end for loop
-use a max function or sort list to find max
-print item and cost
end while loop
close new file

Don't know python, but you should be able to figure out a way to code each step in any language

_________________
Ass&Titties: http://www.youtube.com/watch?v=tPVHoD__6CI
Image
Image
IGN: Deadlock, KillAndChill, LightsOut


Top
 Profile  
 
 Post subject: Re: Python
PostPosted: Sat Apr 09, 2011 2:27 am 
Forum God
User avatar
Offline

Joined: Jan 2006
Posts: 9544
Location: London, United Kingdom
never used pyton but having it show the highest value shouldnt be a problem, if it was in php id have a script work with a server or even just a simple database to store each 'bid' and have a recall that searches for the highest value in that catagory which would display it. hard part would be having it accept new bids from an outside source thats something i cant do even in php but im a bit of a noob at it so yeh, but just the recall part and even it creating a new entry in a database isnt too hard

but as i said never worked with python but id imagine you could use a similar process, same with most program lanuages

_________________
Image


I am not online much if you wish to get hold of me send me a private message with your email/discord and ill catch up with you.


Top
 Profile  
 
 Post subject: Re: Python
PostPosted: Sat Apr 09, 2011 3:02 am 
Ex-Staff
User avatar
Offline

Joined: Jan 2008
Posts: 2761
Location: /wave
I doubt you actually researched it but here's some pseudo-code for you anyways:
Code:
current_group = null
max_number = 0
file = open('/google/me/input.txt','r')
for line in file:
  if line is a number and > max_number then set as max_number
  if line is a word (any check will do, a simple regex ^\w+ for example) and current_group = null then current_group = word
  else output current_group,max_number to where ever you need set current_group = word max_number = 0 and call method again


Basic idea, I'd write something more elegant with this only as the foundation if you're turning it in for a grade though.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group