Follow us on Twitter!
Imagination is more valuable than knowledge - Albert Einstein
Wednesday, April 23, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 15
Guests Online: 13
Members Online: 2

Registered Members: 82886
Newest Member: The Slummy
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Need Some help with Python

Darkracer13
Member



Posts: 11
Location:
Joined: 24.10.09
Rank:
Guest
Posted on 24-02-10 17:58
Ok my friend has been playing a game on Facebook called Farmville and i wanted to make a program out of python to tell him which crops are more profitable. well i ran into problems with trying to substart 15 from a number the user puts in. If you can help here is the code soruce.
Code
import string

e2 = raw_input("Enter Plants Name: >> ")
f2 = raw_input("Enter a Plants Cost: >> ")
g2 = raw_input("Enter The Reward Cost: >>")
h2 = raw_input("Enter The Number of crops you can plant up to 2 Days: >> ")
a2 = 15
b2 = g2
c2 = h2
t1 = f2 count-15

print "%d Cost %d.", profit (e2,t1)





www.hellboundhackers.org/sig/r/43558.png
Author

RE: Need Some help with Python


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-02-10 18:02
what? do you mean f2-15? whats the error you're getting.

If your post doesn't make sense how are we to help you?


Author

RE: Need Some help with Python

Darkracer13
Member



Posts: 11
Location:
Joined: 24.10.09
Rank:
Guest
Posted on 24-02-10 18:09
when i do the f2-15 i get a
TypeError: unsupported operand type(s) for -: 'str' and 'int'

so i looked around and tried some things and none of them worked. count- was the last on i tried

im new to python and tring to figure the math parts out.


www.hellboundhackers.org/sig/r/43558.png

Edited by Darkracer13 on 24-02-10 18:17
Author

RE: Need Some help with Python

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 24-02-10 18:18
Darkracer13 wrote:
when i do the f2-15 i get a
TypeError: unsupported operand type(s) for -: 'str' and 'int'

so i looked around and try thing and none of them worked. count- was the last on i tryed

raw_input returns a string. You need to typecast it to an int or float (I don't know which you need in your case). Something like this:
Code
e2 = raw_input("Enter Plants Name: >> ")
f2 = float( raw_input("Enter a Plants Cost: >> "))
g2 = float(raw_input("Enter The Reward Cost: >>"))
h2 = int(raw_input("Enter The Number of crops you can plant up to 2 Days: >> "))
a2 = 15
t1 = f2 count-15 #I don't know what count is supposed to be.

print "%s Cost %d.", profit (e2,t1)#note the change on this line. %d is a decimal number




And you really ought to think about giving your variables more meaningful names.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg


Edited by ynori7 on 24-02-10 18:23
ynori7 http://halls-of-valhalla.org
Author

RE: Need Some help with Python


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 24-02-10 18:20
raw_input always returns a string. Strings cannot be used in mathematical operations without being typecasted and example would be ...

Code

f2 = raw_input("Enter a Plants Cost: >> ")
f2= int(f2)





Now f2 would be an integer instead of a string. Note this does not do error checking to make sure it is a valid input according to your specifications.

//
Love it when I make a post and its out done with a better response too prior to hitting the submit button =P Anyways you have your answer.




Edited by on 24-02-10 18:23
Author

RE: Need Some help with Python

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 24-02-10 18:25
MoshBat wrote:
ynori beat us.

I'm a quick-draw. Wink

@OP - In case you didn't notice, I edited my post to point out a mistake in your print statement as well.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: Need Some help with Python

stranac
Member



Posts: 149
Location:
Joined: 15.11.08
Rank:
God
Posted on 24-02-10 18:26
ynori7 wrote:
raw_input returns a string. You need to typecast it to an int or float .


Or you could simply use input() which will return a number
Author

RE: Need Some help with Python

Darkracer13
Member



Posts: 11
Location:
Joined: 24.10.09
Rank:
Guest
Posted on 24-02-10 18:29
Thanks for the tips i will edit it. would it worked if i did
Code
import string

Name = raw_input("Enter Plants Name: >> ")
Plots = raw_input("Enter Number of plots you are going to Plant on: >> ")
Cost = raw_input("Enter a Plants Cost: >> ")
Gain = raw_input("Enter The Amount Gained from a single Plant: >>")
Time = raw_input("Enter The Number of crops you can plant up to 2 Days: >> ")
Ploting = int(Plots)*15

profit = a2

print "Your Profit is:", a2



and then subtracting it from the total money gained. this is in the beta form with out all the other math stuff or.. would what you guys said require me not to do all of this?? like the int(Plots)*15


www.hellboundhackers.org/sig/r/43558.png
Author

RE: Need Some help with Python

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 24-02-10 18:43
Darkracer13 wrote:
would what you guys said require me not to do all of this?? like the int(Plots)*15

How hard is it to say int()? And I wouldn't recommend the input function because it's unsafe. It evaluates the input as a python command. For your case it'd probably be fine, but I'd get into the habit of not using it.

And why do you keep importing string?


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: Need Some help with Python

Darkracer13
Member



Posts: 11
Location:
Joined: 24.10.09
Rank:
Guest
Posted on 24-02-10 18:46
if its the import string at the top i really dont know what to change it to. but i have changed the code around a little bit and it works so far.
Code
import string

Name = raw_input("Enter Plants Name: >> ")
Plots = float( raw_input("Enter Number of plots you are going to Plant on: >> "))
Costs = float( raw_input("Enter a Plants Cost: >> "))
Gained = float( raw_input("Enter The Amount Gained: >>"))
Time = int(raw_input("Enter The Number of crops you can plant up to 2 Days: >> "))
a2 = Plots*15


print "The Cost of Plowing is:", (a2)





www.hellboundhackers.org/sig/r/43558.png
Author

RE: Need Some help with Python

stranac
Member



Posts: 149
Location:
Joined: 15.11.08
Rank:
God
Posted on 24-02-10 18:48
If you're not using the string module, don't import it. Importing a module is not something you must do.
Author

RE: Need Some help with Python

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
Posted on 24-02-10 19:01
you could also use atof from the locale module if you really feel you need to import something
Code

import locale

string = raw_input("enter a number")

stringToFloatPoint = locale.atof(string)

print stringToFloatPoint





locale.atof() = pull float point from string
locale.atoi() = pull integer from string



Edited by techb on 24-02-10 19:03
kbcarte.wordpress.com
Author

RE: Need Some help with Python

Darkracer13
Member



Posts: 11
Location:
Joined: 24.10.09
Rank:
Guest
Posted on 24-02-10 19:29
Ok i got it. this is what i have ended up with with your guys help. its my first program with python. Thanks
Code

money = float( raw_input("Enter how much money you have: >>"))
name = raw_input("Enter Plants Name: >> ")
plots = float( raw_input("Enter Number of plots you are going to Plant on: >> "))
costs = float( raw_input("Enter a Plants Cost: >> "))
earned = float( raw_input("Enter The Amount Earned from Sell: >>"))
time = int(raw_input("Enter The Number of crops you can plant up to 2 Days: >> "))


cost_of_plots = plots*15
cost_of_planting = plots*costs
total_cost = cost_of_plots+cost_of_planting
total_income = earned*plots
money_lost = money-total_cost
mod_income = total_income-total_cost
monetary_adjustment = mod_income+money_lost




print "The Cost of Plowing is:", (cost_of_plots)
print "The Cost of Planting is:", (cost_of_planting)
print "So far it Costs: ", (total_cost)
print "Which brings your money to: ", (money_lost)
print "Your Profits are: ", (mod_income)
print "Your Money with Profits is: ", (monetary_adjustment)



all the Profits weren't right. But i fixed it


www.hellboundhackers.org/sig/r/43558.png

Edited by Darkracer13 on 24-02-10 20:02