473,698 Members | 2,025 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 1665
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
1701
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
3481
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
4644
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
1397
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
1348
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
1383
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
7953
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
3603
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
36639
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
8598
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
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
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...
0
8855
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...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
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
5857
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();...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.