[Tutor] this is hard
Alan Trautman
ATrautman@perryjudds.com
Mon, 19 Aug 2002 14:57:23 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C247BA.A27AEF50
Content-Type: text/plain;
charset="iso-8859-1"
raw_input and many other Python functions return strings (i.e...
alphanumeric items a,b,c) that must be thought of as text. This includes
numbers that are not explicitly defined as numbers (int,float). Therefore
you cannot compare the value 1.0 with the string value 1 and get the same
thing. The function raw_input is returning a string which you are then
comparing to a integer 1.
if input ==1:
These must be of the same type to compare. Either you must convert the
integer to a string:
if input =='1':
or convert the value of input to an integer:
if int(input) ==1:
I do not recommend the second as many errors can be created unless you have
perfect users and then you have to catch them all:) This also work for your
prior posting. I recommend reading any good text including the Python
website for information about types as without a basic understanding it is
very hard to do anything.
Peace
[Alan Trautman]
-----Original Message-----
From: melvin terry [mailto:espo89@msn.com]
Sent: Monday, August 19, 2002 2:46 PM
To: Pythontutor
Subject: [Tutor] this is hard
why wont this work? When you type 1 noting happenes
#welcome
print "welcome ryan I just wanted you to have a second calculator!"
print "here you can ahose from what you would like o ind the rarea of..."
input = raw_input("type 1 for a rectangle")
if input == 1:
heigth = input("please type height here:")
width = input ("please type width here:")
area = height*width
print "The area is"
area
_____
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
<http://explorer.msn.com>
------_=_NextPart_001_01C247BA.A27AEF50
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2716.2200" name=GENERATOR></HEAD>
<BODY
style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; FONT: 10pt verdana; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none">
<DIV><SPAN class=940465319-19082002><FONT face=verdana>raw_input and many other
Python functions return strings (i.e... alphanumeric items a,b,c) that must be
thought of as text. This includes numbers that are not explicitly defined as
numbers (int,float). Therefore you cannot compare the value 1.0 with the string
value 1 and get the same thing. The function raw_input is returning a string
which you are then comparing to a integer 1.</FONT></SPAN></DIV>
<DIV><SPAN class=940465319-19082002>if input ==1:</SPAN></DIV>
<DIV><SPAN class=940465319-19082002></SPAN> </DIV>
<DIV><SPAN class=940465319-19082002><FONT face=verdana>These must be of the same
type to compare. Either you must convert the integer to a
string:</FONT></SPAN></DIV>
<DIV><SPAN class=940465319-19082002>if input =='1':</SPAN></DIV>
<DIV><SPAN class=940465319-19082002><FONT
face=verdana></FONT></SPAN> </DIV>
<DIV><SPAN class=940465319-19082002><FONT face=verdana>or convert the value of
input to an integer:</FONT></SPAN></DIV>
<DIV><SPAN class=940465319-19082002>if int(input) ==1:</SPAN></DIV>
<DIV><SPAN class=940465319-19082002></SPAN> </DIV>
<DIV><SPAN class=940465319-19082002><FONT face=verdana>I do not recommend the
second as many errors can be created unless you have perfect users and then you
have to catch them all:) This also work for your prior posting. I
recommend reading any good text including the Python website for information
about types as without a basic understanding it is very hard to do anything.
</FONT></SPAN></DIV>
<DIV><SPAN class=940465319-19082002></SPAN><FONT face=Tahoma><FONT
face=verdana></FONT></FONT> </DIV>
<DIV><FONT face=Tahoma><SPAN class=940465319-19082002><FONT
face=Verdana>Peace</FONT></SPAN></DIV>
<DIV><BR><SPAN class=940465319-19082002><FONT face=verdana>[Alan
Trautman] </FONT></SPAN></DIV>
<DIV><SPAN class=940465319-19082002></SPAN> </DIV>
<DIV><SPAN class=940465319-19082002> </SPAN>-----Original
Message-----<BR><B>From:</B> melvin terry
[mailto:espo89@msn.com]<BR><B>Sent:</B> Monday, August 19, 2002 2:46
PM<BR><B>To:</B> Pythontutor<BR><B>Subject:</B> [Tutor] this is
hard<BR><BR></DIV></FONT>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV>why wont this work? When you type 1 noting happenes</DIV>
<DIV> </DIV>
<DIV>#welcome<BR>print "welcome ryan I just wanted you to have a second
calculator!"<BR>print "here you can ahose from what you would like o ind the
rarea of..."<BR>input = raw_input("type 1 for a rectangle")<BR>if input ==
1:<BR> <BR> heigth = input("please
type height here:")<BR> width = input ("please type
width here:")<BR> area =
height*width<BR> print "The area
is"<BR> area<BR></DIV><BR clear=all>
<HR>
Get more from the Web. FREE MSN Explorer download : <A
href="http://explorer.msn.com">http://explorer.msn.com</A><BR>
<P></P></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C247BA.A27AEF50--