Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
AMD Damo
Gerbil Jedi
Topic Author
Posts: 1663
Joined: Wed Jun 07, 2006 3:35 am
Location: Australia, the backwater of all things Technology!

Python problem

Mon Jun 01, 2009 4:24 am

I'm having a bit of trouble with python at the moment, I need to create an if statement but i'm not sure on how to go about it, example, if something equals 30, than the price is $90, but after that 30 minutes, every 15 minutes after is another $50 on top of that $90?

How would i go about doing that?

Thanks in advance.
Image
 
FireGryphon
Darth Gerbil
Posts: 7729
Joined: Sat Apr 24, 2004 7:53 pm
Location: the abyss into which you gaze

Re: Python problem

Mon Jun 01, 2009 4:29 am

Not sure of the Python syntax, but in the loop I'd check the system clock to see if the proper amount of time is passed, and set the other variables appropriately.
Sheep Rustlers in the sky! <S> Slapt | <S> FUI | Air Warrior II/III
 
AMD Damo
Gerbil Jedi
Topic Author
Posts: 1663
Joined: Wed Jun 07, 2006 3:35 am
Location: Australia, the backwater of all things Technology!

Re: Python problem

Mon Jun 01, 2009 4:57 am

FireGryphon wrote:
Not sure of the Python syntax, but in the loop I'd check the system clock to see if the proper amount of time is passed, and set the other variables appropriately.


Hmm, I mean as in you put 30 into a variable, it will equal $90 in the total price variable, but if that goes up to 45, it will be +$50 on top of the original $90 and so on so forth.
Image
 
cheesyking
Minister of Gerbil Affairs
Posts: 2756
Joined: Sun Jan 25, 2004 7:52 am
Location: That London (or so I'm told)
Contact:

Re: Python problem

Mon Jun 01, 2009 6:09 am

Something like this?

time=1
while time > 0:
        time = int(raw_input("Please enter a time: "))
        total=90.0
        if time > 30:
                for x in xrange(30,time,15):
                        total+=50
        print total


That for loop is a bit lame... should be something more like total+=((time-30)/15)*50 but that would only take into account whole 15 minute blocks.
Fernando!
Your mother ate my dog!
 
AMD Damo
Gerbil Jedi
Topic Author
Posts: 1663
Joined: Wed Jun 07, 2006 3:35 am
Location: Australia, the backwater of all things Technology!

Re: Python problem

Tue Jun 02, 2009 4:39 am

Got it working with my own maths thing I came up with, thanks for the help :)
Image

Who is online

Users browsing this forum: No registered users and 0 guests
GZIP: On