Talk:Non-Programmer's Tutorial for Python 2.0/Who Goes There?
From Wikibooks, the open-content textbooks collection
Contents |
[edit] input() vs. raw_input()
The example code on this page was broken for floats. I see that the use of int(raw_input()) drives the user away from input(), which can be dangerous. In my view it is needless complication. The focus of this manual should be on basic concepts. Allowing the use of input() keeps the user from having to worry too much about data types and lets them move on to other things. The text currently says, "raw_input() returns a string while input() returns a number." I think it makes good sense to keep things at this level and to drop int(raw_input()) from the example code. Thoughts? Zastard (talk) 17:41, 14 April 2008 (UTC)
- Well, I guess this becomes a mute point when we switch the tutorial over to python 3000, in which input always returns a string. Since that will be happening later this year (or maybe the tutorial will be forked) I think we will have to just explain int(raw_input()). Jrincayc (talk) 03:11, 15 April 2008 (UTC)
[edit] = vs ==
The use of == won't be understood by non-programmers. It hasn't been introduced yet I don't think, so using it casually won't work. Dooglus 19:46, 30 April 2006 (UTC) dooglus
- I agree and think we should change/remove the following section (including the example):
- If you want to use an actual value, you must use quotation marks. value1 == Pim; value2 == "Pim"
-
- Both look the same, but in the first one Python checks if the value stored in the variable value1 is the same as the value stored in the variable Pim. In the second one, Python checks if the string (the actual letters P,i, and m) are the same as in value2 (continue this tutorial for more explanation about strings and about the ==).
- Especially the "actual value" is kind of confusing. Siebengang (talk) 07:57, 15 April 2008 (UTC)
- I agree. It is confusing. I see what it's trying to accomplish though. The question it's trying to answer is "What's the difference between the variable pim and the string "pim"". This is a fairly abstract idea, and in as much as we should be trying to avoid those, for now, I think it's save to remove this. If the user is very curious they will be better served learning this by experimentation anyway. Zastard (talk) 18:09, 17 April 2008 (UTC)
[edit] Example Rates_times.py Error
When running this program I received an error because I input a decimal number but the input is actually an integer. I am new to python. Contact User:Camilo Sanchez at wikipedia.
int()tries to convert anything into an integer.raw_input()returns keyboard input as a string. If the argument ofint()is a string, the conversion will only work with strings containing an integer (as"1234"), not any other number (e.g."1234.56").
- Replace the
int()function withfloat(), and it will work with floats, too. Example:
-
rate = float(raw_input("Rate: "))
- Siebengang (talk) 08:59, 11 April 2008 (UTC)
[edit] program
i get an error with this:
num = input("Type in a Number: ")
str = raw_input("Type in a String: ")
print "num =", num
print "num is a ",type(num)
print "num * 2 =",num*2
print "str =", str
print "str is a ",type(str)
print "str * 2 =",str*2
Type in a number: 12.34
Type in a string: hello
num = 12.34
num is a <type 'float'>
num * 2 = 24.68
str = hello
str is a
Traceback (most recent call last):
File "/home/exter/compexperiments/hello.py", line 7, in -toplevel- print "str is a ",type(srt)
NameError: name 'srt' is not defined
i'm using python 2.4.4
tk 8.4
idle 1.1.4
It's a typo, it should be str instead of srt. 89.172.27.156 13:41, 21 August 2007 (UTC)
This doesn't work for Python 3.0. How about a revision for the new version?