Code Point
September 10, 2010, 06:03:41 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Geshi Sintax Hilighting Mod Installed. Tens of languages available.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Can someone please help me with this...  (Read 2368 times)
jksdua
Jr. Member
*

Karma: 0
Offline Offline

Posts: 1


« on: July 20, 2007, 11:09:37 AM »

Hey,

I just started working on Python today. There is a competition which is being hosted by the school. I am practicing and have an error coming up on this code. i am trying to make a module where it asks for the cost of your hard drive and then the size and tells the price/gb. it isn't working. i think the problem has to do with the division operator. can someone suggest a solution. this is the code:

print "Welcome to Jaap's Hard Drive Calculator"
price = raw_input ("What is the price of the hard drive you intend to purchase? Please do not type GB or TB at the end.")
model = raw_input ("What is the size of the hard drive you intend to purchase? Please do not add the currency symbol.")
print "The cost/GB is", price/model
print "Thank you for using Jaap's services"
Logged
Alter Lobo
Global Moderator
Jr. Member
*****

Karma: 10
Offline Offline

Posts: 65


« Reply #1 on: July 20, 2007, 12:52:40 PM »

You must cast the inputed strings to floats:

Code
print "Welcome to Jaap's Hard Drive Calculator"
price = float(raw_input ("What is the price of the hard drive you intend to purchase? Please do not type GB or TB at the end."))
model = float(raw_input ("What is the size of the hard drive you intend to purchase? Please do not add the currency symbol."))
print "The cost/GB is", price/model
print "Thank you for using Jaap's services"

Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!