473,587 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accepting text input

I'm pretty new to Python, but this has really bugged me. I can't find a
way around it.
The problem is that, when I use raw_input("sajf asjdf") whatever, or
input("dsjfadsj fa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.
Jun 27 '08 #1
7 1662
Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't find a
way around it.
The problem is that, when I use raw_input("sajf asjdf") whatever, or
input("dsjfadsj fa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.

Oh, wow. I feel so stupid. Please disregard this message. <_<

I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value. Then
when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)

Collin
Jun 27 '08 #2
En Mon, 12 May 2008 01:54:28 -0300, Collin <co*********@sh aw.caescribió:
Collin wrote:
>I'm pretty new to Python, but this has really bugged me. I can't find a
way around it.
The problem is that, when I use raw_input("sajf asjdf") whatever, or
input("dsjfads jfa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.


Oh, wow. I feel so stupid. Please disregard this message. <_<
No need to apologize...
I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value. Then
when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)
The usual way for Python<3.0 is:

answer = raw_input("Test test test ").lower()
if answer == "yes":
...

The input() function evaluates user input as an expression: if he types 2+5 the input() function returns the integer 7. I would never use input() in a program - it's way too unsafe; use always raw_input instead.

--
Gabriel Genellina

Jun 27 '08 #3
Gabriel Genellina wrote:
En Mon, 12 May 2008 01:54:28 -0300, Collin <co*********@sh aw.caescribió:
>Collin wrote:
>>I'm pretty new to Python, but this has really bugged me. I can't find a
way around it.
The problem is that, when I use raw_input("sajf asjdf") whatever, or
input("dsjfad sjfa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.

Oh, wow. I feel so stupid. Please disregard this message. <_<

No need to apologize...
>I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value. Then
when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)

The usual way for Python<3.0 is:

answer = raw_input("Test test test ").lower()
if answer == "yes":
...

The input() function evaluates user input as an expression: if he types 2+5 the input() function returns the integer 7. I would never use input() in a program - it's way too unsafe; use always raw_input instead.
If I use it like that, do I have to import anything to have the .lower()
work? And if I do, what does the .lower() signify?
Jun 27 '08 #4
On Wed, 14 May 2008 11:02:36 +1000, Collin <co*********@sh aw.cawrote:
Gabriel Genellina wrote:
>En Mon, 12 May 2008 01:54:28 -0300, Collin <co*********@sh aw.ca
escribió:
>>Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't find
a
way around it.
The problem is that, when I use raw_input("sajf asjdf") whatever, or
input("dsjfa dsjfa"), you can only have numerical values as answers.

Any help would be appreciated. Thanks.

Oh, wow. I feel so stupid. Please disregard this message. <_<
No need to apologize...
>>I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value. Then
when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)
The usual way for Python<3.0 is:
answer = raw_input("Test test test ").lower()
if answer == "yes":
...
The input() function evaluates user input as an expression: if he
types 2+5 the input() function returns the integer 7. I would never use
input() in a program - it's way too unsafe; use always raw_input
instead.

If I use it like that, do I have to import anything to have the .lower()
work? And if I do, what does the .lower() signify?
--
http://mail.python.org/mailman/listinfo/python-list
You don't need to import any module to use ".lower()"; it is a method ofa
string. raw_input() returns a string, so you can use methods of a string.

Try the following statement to see what happens:
"ABCDE".low er()

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #5
Kam-Hung Soh wrote:
On Wed, 14 May 2008 11:02:36 +1000, Collin <co*********@sh aw.cawrote:
>Gabriel Genellina wrote:
>>En Mon, 12 May 2008 01:54:28 -0300, Collin <co*********@sh aw.ca>
escribió:

Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't
find a
way around it.
>
>
The problem is that, when I use raw_input("sajf asjdf") whatever, or
input("dsjf adsjfa"), you can only have numerical values as answers.
>
Any help would be appreciated. Thanks.

Oh, wow. I feel so stupid. Please disregard this message. <_<
No need to apologize...

I read the error message just now a bit more carefully, and I tried
something. I tried defining "yes" as some random numerical value. Then
when I did:
(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)
The usual way for Python<3.0 is:
answer = raw_input("Test test test ").lower()
if answer == "yes":
...
The input() function evaluates user input as an expression: if he
types 2+5 the input() function returns the integer 7. I would never
use input() in a program - it's way too unsafe; use always raw_input
instead.

If I use it like that, do I have to import anything to have the
.lower() work? And if I do, what does the .lower() signify?
--
http://mail.python.org/mailman/listinfo/python-list

You don't need to import any module to use ".lower()"; it is a method of
a string. raw_input() returns a string, so you can use methods of a
string.

Try the following statement to see what happens:
"ABCDE".low er()
So the .lower() string method is just to convert the string to lowercase
letters so that you don't have to type a bunch of if - then statements
in both cases, I'm assuming?
Jun 27 '08 #6
On Thu, 15 May 2008 02:36:29 GMT
Collin <co*********@sh aw.cawrote:
So the .lower() string method is just to convert the string to lowercase
letters so that you don't have to type a bunch of if - then statements
in both cases, I'm assuming?
You can also type:

dir(str)

to get a list of all the methods you can call on a string object. If you see anything interesting, then type:

help(str.<metho d_name>) # e.g. help(str.split)

to find out how it works. :)
Jun 27 '08 #7
On Thu, 15 May 2008 12:36:29 +1000, Collin <co*********@sh aw.cawrote:
Kam-Hung Soh wrote:
>On Wed, 14 May 2008 11:02:36 +1000, Collin <co*********@sh aw.cawrote:
>>Gabriel Genellina wrote:
En Mon, 12 May 2008 01:54:28 -0300, Collin <co*********@sh aw.ca
escribió:

Collin wrote:
>I'm pretty new to Python, but this has really bugged me. I can't
>find a
>way around it.
>>
>>
>The problem is that, when I use raw_input("sajf asjdf") whatever, or
>input("dsj fadsjfa"), you can only have numerical values as answers.
>>
>Any help would be appreciated. Thanks.
>
Oh, wow. I feel so stupid. Please disregard this message. <_<
No need to apologize...

I read the error message just now a bit more carefully, and I tried
something . I tried defining "yes" as some random numerical value.
Then
when I did:
(example code)
>
yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"
>
(example code off)
The usual way for Python<3.0 is:
answer = raw_input("Test test test ").lower()
if answer == "yes":
...
The input() function evaluates user input as an expression: if he
types 2+5 the input() function returns the integer 7. I would never
use input() in a program - it's way too unsafe; use always raw_input
instead.
If I use it like that, do I have to import anything to have the
.lower() work? And if I do, what does the .lower() signify?
-- http://mail.python.org/mailman/listinfo/python-list
You don't need to import any module to use ".lower()"; it is a method
of a string. raw_input() returns a string, so you can use methods ofa
string.
Try the following statement to see what happens:
"ABCDE".lower( )

So the .lower() string method is just to convert the string to lowercase
letters so that you don't have to type a bunch of if - then statements
in both cases, I'm assuming?
--
http://mail.python.org/mailman/listinfo/python-list
That's right. If you normalize your input to all lower case or upper
case, you make it easier to process user input.

Regards,

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1700
by: Ge B | last post by:
Hi, New to PHP, I was trying to figure out how to make such a form: Data: When I enter a data and click the button, the data gets added to a list (and preferably the updated list is displayed on the same page). This repeats until I click button.
2
3480
by: Rikkert | last post by:
I am trying to make an Edit control that accepts only numbers and one point (i.e. only accepting input of type 'double' or 'float'). Can this be done without using MFC? The standard options for the Edit control seem to be either accepting all character input, or only integer number input, which doesn't quite cut it... Any tips are appreciated!
4
4640
by: MattBell | last post by:
I've tried to search for an answer to this without much success, and I think it's probably a common thing to do: I have a web service I want to accept an XmlDocument as an argument which conforms to a specific XSD that is defined. Right now when I declare XmlDocument as my argument, it puts the old xml:any type in. How do I change that to reflect the XSD that I'm looking for? Thanks for any Help!
9
1392
by: Jim Langston | last post by:
This is something I've been thinking about creating, and am trying to get the pieces together. I want to be able to assign values in a method accepting different types. I.E. MyInstance.MyMethod("IntField") = 1; MyInstance.MyMethod("FloatField") = 2.34f; MyInstance.MyMethod("StringField") = std::string("Hello");
6
1340
by: rh0dium | last post by:
Hi Experts!! I am trying to get the following little snippet to push my data to the function func(). What I would expect to happen is it to print out the contents of a and loglevel. But it's not working. Can someone please help me out. ---------<snip>-------------- #!/usr/bin/env python
0
1379
chigasakigaijin
by: chigasakigaijin | last post by:
Hi all! This is my first post in this forum. Looking forward to learning alot! I'm still a beginner at Python, but have grasped all the major concepts in "How to Think Like a Computer Scientist." I'm trying to branch out a bit and get some more control over how my console apps are displayed. I don't want to jump into a full-fledged GUI like TkInter just yet, though, so I wanted to see if I could get more control over the Windows Console. ...
2
7939
by: Vbbeginner07 | last post by:
Hi all Wonder if anyone can help me out to solve this: please find the code of textbox that accepts only characters and one textbox that accepts only numbers: (vb) textbox for accepting characters: If txtname.Text = "" Then MsgBox "enter the name", vbOKOnly, "PAYROLL"
2
3602
by: psychofish25 | last post by:
I am trying to make a simple random number generator GUI, and for some reason I get an error trying to take the text out txt1 and txt2. Why isn't this working? The error says AttributeError: 'NoneType' object has no attribute 'get' from Tkinter import * import random class myform: def __init__(self,form): form.wm_title('Random') lbl1=Label(form,text='Low:').grid(row=0) ...
5
36629
by: nidaar | last post by:
From a security point of view, is accepting wildcards like "%" in input parameters of stored procedures against any best practices? As an example, if a user defined function uses "Productname LIKE @ProductName" in WHERE clause of a select statement, and a stored procedure uses the user defined function while passing @ProductName input parameter to the user defined function, is there any security risks? Is there a better way to construct...
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.