0

Here is my code:

def bitcoin_to_usd(btc):
    amount = btc * 527
    print(amount)

btc = input("Input your Bitcoins amount: ")

bitcoin_to_usd(btc)

I want to get Bitcoin number from user then I want to calculate how much USD is it.

That code gives me repetition of the input. Such as if you input 2 it returns 222222222222222222222222.... doesn't calculate it.

My Python version is 3.4.1 and I am using PyCharm.

Any ideas?

5 Answers 5

2

Your code is fine except that you need to convert the result of input, which returns a string, to a number. Let's try float for a floating-point datatype:

def bitcoin_to_usd(btc):
    amount = btc * 527
    print(amount)

btc = float( input("Input your Bitcoins amount: ") )

bitcoin_to_usd(btc)
Sign up to request clarification or add additional context in comments.

Comments

0

In python3.x, input returns a string1, not a number. If you want a number, you should convert the input string to a float or int.

btc = float(input("Input your Bitcoins amount: "))

1This explains the results as well, multiplying a string by an integer causes the string to be concatenated with itself that number of times.

Comments

0

You could use

btc = input("Input your Bitcoins amount: ")

def bitcoin_to_usd(btc):
    amount = btc * 527
    print(amount)


bitcoin_to_usd(btc)

Comments

0

you can try this where the function has no parameter :

    def sum():
        return x+y
    x = int(input("Val of x"))
    y = int(input("Val of y"))
    print(sum())

or you can also try this one where the function has the parameter:

def sum(x,y):
       return x+y
x = int(input("Val of x"))
y = int(input("Val of y"))
print(sum(x,y))

Comments

-1

Use the below line inside your defined function:

amount = float(btc) * 527

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.