Math error when multiplying float by integer in python

Tom1998
def CalculateExchange(currency2,rate):
    currencyamount1 = int(input("Enter the amount: "))
    currencyamount2 = (currencyamount1 * rate)
    print(currencyamount2,currency2)

When multiplying the exchange rate obtained earlier on in the program by the number inputted by the user, instead of it outputting an actual number, it just outputs the amount entered in the form of the exchange rate, e.g. when the exchange rate is 5 and the amount entered is 6 it will just output 6.6.6.6.6 , I could really use help, I know this problem probably seems quite insignificant and easy to correct but I'm having trouble trying to sort it out.

asdf

The easiest way to get around an error like this is to cast your int back into a float before multiplying

def CalculateExchange(currency2,rate):
    currencyamount1 = int(input("Enter the amount: "))
    currencyamount2 = (float(currencyamount1) * float(rate))
    print(currencyamount2,currency2)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiplying an integer by a float literal - is the "F" required?

From Dev

Python - Finding and multiplying an integer after specific word

From Dev

Python ValueError when multiplying integers

From Dev

Integer/Float Typeerror in Python

From Dev

Converting String to an Integer/float when reading from a csv file in Python

From Dev

Swift: Error when multiplying four Double variables

From Dev

Why is float64 cast to int when multiplying with a list?

From Dev

Invalid result when multiplying negative Duration value by a negative integer

From Dev

Python math logic error

From Dev

Regex to intercept integer and float in python

From Dev

python: float number like integer

From Dev

Python: True if variable is integer or float

From Dev

convert unsigned integer to float in python

From Dev

python dataframe converts integer to float

From Dev

Is there a way to print the math that makes an integer in Python?

From Dev

Multiplying a float Number to a Function in Python and getting can't multiply sequence by non-int of type 'float'

From Dev

Multiplying a float Number to a Function in Python and getting can't multiply sequence by non-int of type 'float'

From Dev

Syntax error when multiplying variables in VB.NET

From Dev

Error 1004 when multiplying cell values based on criteria

From Dev

Error when adding parenthesis in multiplying int and double in java why?

From Dev

Error when adding parenthesis in multiplying int and double in java why?

From Dev

Syntax error when multiplying variables in VB.NET

From Dev

Error when trying to convert a column with string in Python Pandas to Float

From Dev

I keep getting this error for my simple python program: "TypeError: 'float' object cannot be interpreted as an integer"

From Dev

Infinite loop when assigning a float to an integer

From Dev

Explain the output when converting Float to integer?

From Dev

How does Float round when converting it into integer

From Dev

How to divide float by integer when both are variables?

From Dev

pandas rounding when converting float to integer

Related Related

  1. 1

    Multiplying an integer by a float literal - is the "F" required?

  2. 2

    Python - Finding and multiplying an integer after specific word

  3. 3

    Python ValueError when multiplying integers

  4. 4

    Integer/Float Typeerror in Python

  5. 5

    Converting String to an Integer/float when reading from a csv file in Python

  6. 6

    Swift: Error when multiplying four Double variables

  7. 7

    Why is float64 cast to int when multiplying with a list?

  8. 8

    Invalid result when multiplying negative Duration value by a negative integer

  9. 9

    Python math logic error

  10. 10

    Regex to intercept integer and float in python

  11. 11

    python: float number like integer

  12. 12

    Python: True if variable is integer or float

  13. 13

    convert unsigned integer to float in python

  14. 14

    python dataframe converts integer to float

  15. 15

    Is there a way to print the math that makes an integer in Python?

  16. 16

    Multiplying a float Number to a Function in Python and getting can't multiply sequence by non-int of type 'float'

  17. 17

    Multiplying a float Number to a Function in Python and getting can't multiply sequence by non-int of type 'float'

  18. 18

    Syntax error when multiplying variables in VB.NET

  19. 19

    Error 1004 when multiplying cell values based on criteria

  20. 20

    Error when adding parenthesis in multiplying int and double in java why?

  21. 21

    Error when adding parenthesis in multiplying int and double in java why?

  22. 22

    Syntax error when multiplying variables in VB.NET

  23. 23

    Error when trying to convert a column with string in Python Pandas to Float

  24. 24

    I keep getting this error for my simple python program: "TypeError: 'float' object cannot be interpreted as an integer"

  25. 25

    Infinite loop when assigning a float to an integer

  26. 26

    Explain the output when converting Float to integer?

  27. 27

    How does Float round when converting it into integer

  28. 28

    How to divide float by integer when both are variables?

  29. 29

    pandas rounding when converting float to integer

HotTag

Archive