FirstAscent
|
|
October 13, 2013, 05:09:10 PM |
|
So, unless you want to draw erroneous conclusions about how to program, as has become glaringly obvious in this little episode, I suggest you only test your code using your local python interpreter.
|
|
|
|
01BTC10
VIP
Hero Member
Offline
Activity: 756
Merit: 503
|
|
October 13, 2013, 05:12:13 PM |
|
So, unless you want to draw erroneous conclusions about how to program, as has become glaringly obvious in this little episode, I suggest you only test your code using your local python interpreter.
I will; however, the online interpreter is the only way to submit our work for the course.
|
|
|
|
FirstAscent
|
|
October 13, 2013, 05:20:54 PM |
|
So, unless you want to draw erroneous conclusions about how to program, as has become glaringly obvious in this little episode, I suggest you only test your code using your local python interpreter.
I will; however, the online interpreter is the only way to submit our work for the course. Even so, the function was not the problem. Run this online: def miles_to_km(miles): return miles * 1.60934
print miles_to_km(1)
|
|
|
|
FirstAscent
|
|
October 13, 2013, 05:22:09 PM |
|
Even further proof: here we're guaranteeing that we're passing an integer into the function: def miles_to_km(miles): return miles * 1.60934
print miles_to_km(int(1))
|
|
|
|
01BTC10
VIP
Hero Member
Offline
Activity: 756
Merit: 503
|
|
October 13, 2013, 05:23:20 PM |
|
Even further proof: here we're guaranteeing that we're passing an integer into the function: def miles_to_km(miles): return miles * 1.60934
print miles_to_km(int(1))
Yes, I know this is how I did it the first time but it doesn't works using input() in the online version.
|
|
|
|
FirstAscent
|
|
October 13, 2013, 05:26:35 PM |
|
def miles_to_km(miles): return miles * 1.60934
miles_input = input('Please input miles to convert in km: ') print miles_to_km(float(miles_input))
What's likely happening here is that when querying for input, you're getting a string. What you want is a number. You don't know if the string, when converted to a number, has a decimal place or not, so you take the safe route and convert it to a float. But this is all about preparing the arguments for the function. The function should expect a number (int or float) and receive that.
|
|
|
|
Peter Lambert
|
|
October 13, 2013, 07:57:06 PM |
|
I'm pretty sure I know what your problem is. First, what version of Python are you using. Type python at the command prompt.
There is no command prompt. It's a web browser implementation for the course. It works fine with codeskulptor but throw an error with python 2.7.3 on my computer. Traceback (most recent call last): File "test.py", line 13, in <module> print miles_input + " miles = " + str(miles_to_km_no_float(miles_input)) + " km (no float)" TypeError: unsupported operand type(s) for +: 'int' and 'str'
for the print command, intead of adding a bunch of things together, it might be better to use placeholders? print "%f miles = %f km." % (miles_input, miles_to_km_no_float(miles_input))
|
Use CoinBR to trade bitcoin stocks: CoinBR.comThe best place for betting with bitcoin: BitBet.us
|
|
|
FirstAscent
|
|
October 13, 2013, 08:09:44 PM |
|
I'm pretty sure I know what your problem is. First, what version of Python are you using. Type python at the command prompt.
There is no command prompt. It's a web browser implementation for the course. It works fine with codeskulptor but throw an error with python 2.7.3 on my computer. Traceback (most recent call last): File "test.py", line 13, in <module> print miles_input + " miles = " + str(miles_to_km_no_float(miles_input)) + " km (no float)" TypeError: unsupported operand type(s) for +: 'int' and 'str'
for the print command, intead of adding a bunch of things together, it might be better to use placeholders? print "%f miles = %f km." % (miles_input, miles_to_km_no_float(miles_input))
Yes. Such power using C style printf printing. Read up on formatting for printf.
|
|
|
|
01BTC10
VIP
Hero Member
Offline
Activity: 756
Merit: 503
|
|
October 13, 2013, 08:25:17 PM |
|
|
|
|
|
MakeBelieve
|
|
October 13, 2013, 09:37:38 PM |
|
I need to learn python
|
On a mission to make Bitcointalk.org Marketplace a safer place to Buy/Sell/Trade
|
|
|
gangplank (OP)
Newbie
Offline
Activity: 28
Merit: 0
|
|
October 13, 2013, 10:20:39 PM |
|
I need to learn python
Jump aboard with this course! I'm pretty much a beginner so we can assist one another via this thread I'm dedicating 1-2 hours a day to this, just need to make it habit for it to stick in my mind otherwise I'll forget.
|
|
|
|
gangplank (OP)
Newbie
Offline
Activity: 28
Merit: 0
|
|
October 13, 2013, 10:26:39 PM |
|
So, unless you want to draw erroneous conclusions about how to program, as has become glaringly obvious in this little episode, I suggest you only test your code using your local python interpreter.
I don't know if this is related but it only uses the libraries we need to complete the course.
|
|
|
|
MakeBelieve
|
|
October 13, 2013, 10:40:12 PM |
|
I need to learn python
Jump aboard with this course! I'm pretty much a beginner so we can assist one another via this thread I'm dedicating 1-2 hours a day to this, just need to make it habit for it to stick in my mind otherwise I'll forget. Will do. Coursera seems to have other awesome courses too.
|
On a mission to make Bitcointalk.org Marketplace a safer place to Buy/Sell/Trade
|
|
|
Baitty
|
|
October 13, 2013, 10:42:54 PM |
|
There was a thread on this forum with different things people created with python.
|
Currently held as collateral by monbux
|
|
|
jackjack
Legendary
Offline
Activity: 1176
Merit: 1255
May Bitcoin be touched by his Noodly Appendage
|
|
October 14, 2013, 07:29:11 AM Last edit: October 14, 2013, 09:30:12 AM by jackjack |
|
Traceback (most recent call last): File "test.py", line 13, in <module> print miles_input + " miles = " + str(miles_to_km_no_float(miles_input)) + " km (no float)" TypeError: unsupported operand type(s) for +: 'int' and 'str'
intstrFix print str(miles_input) + " miles = " + str(miles_to_km_no_float(miles_input)) + " km (no float)"
|
Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2 Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
|
|
|
MakeBelieve
|
|
October 14, 2013, 08:41:14 AM |
|
I've started the course once again.
|
On a mission to make Bitcointalk.org Marketplace a safer place to Buy/Sell/Trade
|
|
|
FirstAscent
|
|
October 14, 2013, 04:02:36 PM |
|
Traceback (most recent call last): File "test.py", line 13, in <module> print miles_input + " miles = " + str(miles_to_km_no_float(miles_input)) + " km (no float)" TypeError: unsupported operand type(s) for +: 'int' and 'str'
intstrFix print str(miles_input) + " miles = " + str(miles_to_km_no_float(miles_input)) + " km (no float)" It's already been done.
|
|
|
|
01BTC10
VIP
Hero Member
Offline
Activity: 756
Merit: 503
|
|
October 14, 2013, 04:26:28 PM |
|
|
|
|
|
|