LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2006, 09:09 AM   #1
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Rep: Reputation: 30
Python , if s=


Hi there i am hoping some one could help me out with a small problem i am in the process of learning python.I am trying to write an interactive programme,
This is a short example.
if s = raw_input ("hello whats your name? ")
if s=='carmel':
print "Ahh the boss,s wife"

What i would like to know is what if she dont write carmel she rights say carm short of me writing if s=='carm': on a new line is there a shorter way of doing this so i can cover all angles on how she might write her name.
Thanks nige
 
Old 03-23-2006, 09:38 AM   #2
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Code:
if (s == "carm") or (s == "carmel"):
    print "Ahh the boss's wife"
else:
    print "something"
You may also need to take into consideration that she may enter capitals. I would convert the name to all lowercase e.g.
Code:
s = raw_input("Enter you name: ")
s = s.lower()

if (s == "carm") or (s == "carmel"):
    print "Ahh the boss's wife"
else:
    print "something"
 
Old 03-23-2006, 09:41 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
from re import *
s = raw_input ("hello whats your name? ")
if compile(s,I).match('carmel'):
	print "Ahh the boss' wife"
 
Old 03-25-2006, 03:14 PM   #4
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
Thanks for your responses,i have signed up with "python list"
some times it takes a while to get an opinion from there,so i like to ask here as well.The programme i am attempting to write is going slowly but well.I am now trying to add a small amount of tk to it i copied the basics from a tutorial it goes like this.
from Tkinter import *
root = Tk()
w = Label(root, text="Congratulations you have made it this far,just a few more questions")
w.pack()
root.mainloop()
The problem i have is where i have wrote my text it fits it all on to 1 line.I need to know how to start a second line so i can add more text.I f any of you folks find yourself with nothing to do i would appreciate some feedback.
Thanks again, nige.
 
Old 03-26-2006, 06:42 AM   #5
master
Member
 
Registered: Oct 2003
Location: Birmingham/Eng/UK
Distribution: /Debian3.1/suse/Win7/8/10
Posts: 680

Original Poster
Rep: Reputation: 30
to start a second line is quite easy all you do,here is my example.

from Tkinter import *
root = Tk()
w = Label(root, text="Line 1 Congratulations you have made it this far,just\n what next")
w.pack()
root.mainloop()

You will notice all i added was where it says "text=" i added "line 1"
Then to continue my sentance on to a second line i added "\n " without the quotes.
Thanks nige
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM
installing python library's (Python Numeric) Four Linux - Newbie 1 10-16-2005 02:31 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
install python 2.3 ,necssary to remove python 2.2 ngan_yine Linux - Newbie 7 12-28-2003 04:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration