[Tutor] decimal input problem

jtl999 jacksmoo111 at gmail.com
Tue Dec 21 05:26:23 CET 2010


when I try to multiply with a decimal  number in python with the input
this is what i get

 MathCheats Times-Ed by jtl999
Not for decimal numbers due to a bug in the code.
Enter first number: 1.2
Traceback (most recent call last):
  File "Timesed.py", line 18, in <module>
    numberx1 = (int)(raw_input('Enter first number: '))
ValueError: invalid literal for int() with base 10: '1.2'

here is the code
#!/usr/bin/python
# MathCheats Times-Ed by jtl999
# (C) 2010 jtl999
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# The GPL is in the file COPYING
print ("MathCheats Times-Ed by jtl999")
print ("Not for decimal numbers due to a bug in the code.")
numberx1 = (int)(raw_input('Enter first number: '))
numberx2 = (int)(raw_input('Enter second number: '))
print ("The answer was")
print numberx1*numberx2




More information about the Tutor mailing list