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?

Lafexlos
7,7555 gold badges42 silver badges55 bronze badges
asked Sep 9, 2014 at 18:31

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)
answered Sep 9, 2014 at 18:33
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.

Raydel Miranda
14.4k3 gold badges48 silver badges66 bronze badges
answered Sep 9, 2014 at 18:32

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)
Jitesh Prajapati
2,5394 gold badges31 silver badges52 bronze badges
answered May 29, 2019 at 7:16

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))
answered Sep 1, 2022 at 17:54

Comments

-1

Use the below line inside your defined function:

amount = float(btc) * 527
answered May 4, 2018 at 12:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.