Dear Group,
I am trying the following code line:
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Best Regards,
Subhabrata. 13 988
On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Maybe you should describe what the input looks like and what output you
want to have and how the input and output are connected. In words, not in
not very clear code with "numbered names". That's a silly idea and makes
understanding the code very hard. Please use meaningful names!
Ciao,
Marc 'BlackJack' Rintsch
SUBHABRATA wrote:
I am trying the following code line:
def try2(n):
user_line = raw_input("PRINT A STRING:")
user_words = user_line.split()
my_line = "God Godess Heaven Sky"
for word in user_words:
pos = my_line.find(word)
if pos >- 1:
first_char = my_line[pos]
print first_char
elif pos < 0:
missing_word = word
print "It is not found"
print missing_word
else:
print "Error"
s = first_char + " " + missing_word
print s
try2(1)
Do you recognise your code? With that jumpstart you should find the error in
no time ;)
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Yes, use meaningful variables. They won't make your code magically correct
but will make it a lot easier to pinpoint mistakes and false assumptions --
for you and others.
Peter
Sorry if I didn't say that.
The input is a string "Petrol Helium Heaven Sky"
Now, in a3 it is "God Goddess Heaven Sky" is there,
it is matching Heaven and Sky but not Petrol and Helium as they are
not in a3.
Now, as per the code it is giving me an output "S" of "Sky" and
"Helium"
But I was looking for an output of "H S Petrol Helium" and not "S
Helium" meaning all the values of a5 and a6 will be concatenated in s.
Best Regards,
Subhabrata..
Marc 'BlackJack' Rintsch wrote:
On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Maybe you should describe what the input looks like and what output you
want to have and how the input and output are connected. In words, not in
not very clear code with "numbered names". That's a silly idea and makes
understanding the code very hard. Please use meaningful names!
Ciao,
Marc 'BlackJack' Rintsch
Thanx Peter,
I would change my variables next time I would post. And obviously,
thanx for your solution. I am reviewing it, I was also trying out some
solutions.
Best Regards,
Subhabrata.
Peter Otten wrote:
SUBHABRATA wrote:
I am trying the following code line:
def try2(n):
user_line = raw_input("PRINT A STRING:")
user_words = user_line.split()
my_line = "God Godess Heaven Sky"
for word in user_words:
pos = my_line.find(word)
if pos >- 1:
first_char = my_line[pos]
print first_char
elif pos < 0:
missing_word = word
print "It is not found"
print missing_word
else:
print "Error"
s = first_char + " " + missing_word
print s
try2(1)
Do you recognise your code? With that jumpstart you should find the error in
no time ;)
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Yes, use meaningful variables. They won't make your code magically correct
but will make it a lot easier to pinpoint mistakes and false assumptions --
for you and others.
Peter
Hi Peter,
In your code s would print first_char(of the last word)+"
"+missing_word(the last word) I was looking all.
Best Regards,
Subhabrata.
SUBHABRATA wrote:
Sorry if I didn't say that.
The input is a string "Petrol Helium Heaven Sky"
Now, in a3 it is "God Goddess Heaven Sky" is there,
it is matching Heaven and Sky but not Petrol and Helium as they are
not in a3.
Now, as per the code it is giving me an output "S" of "Sky" and
"Helium"
But I was looking for an output of "H S Petrol Helium" and not "S
Helium" meaning all the values of a5 and a6 will be concatenated in s.
Best Regards,
Subhabrata..
Marc 'BlackJack' Rintsch wrote:
On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
>
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Maybe you should describe what the input looks like and what output you
want to have and how the input and output are connected. In words, not in
not very clear code with "numbered names". That's a silly idea and makes
understanding the code very hard. Please use meaningful names!
Ciao,
Marc 'BlackJack' Rintsch
SUBHABRATA wrote:
Thanx Peter,
I would change my variables next time I would post.
No, you should use meaningful variable names when you write your code no
matter whether you plan to post it or not.
And obviously,
thanx for your solution. I am reviewing it, I was also trying out some
solutions.
You misunderstood. I did not modify your code other than changing the
variable names. My hope was that with this modification any errors sprang
to you eye...
Peter
Hi Peter,
Peter Otten wrote:
SUBHABRATA wrote:
Thanx Peter,
I would change my variables next time I would post.
No, you should use meaningful variable names when you write your code no
matter whether you plan to post it or not.
Good You are teaching me something good in life. Thanx.
>
And obviously,
thanx for your solution. I am reviewing it, I was also trying out some
solutions.
You misunderstood. I did not modify your code other than changing the
variable names. My hope was that with this modification any errors sprang
to you eye...
I was seeing that.
I am almost near the solution. You can also try some hands if you
feel.
Best Regards,
Subhabrata.
>
Peter
On Jul 18, 5:40*am, SUBHABRATA <subhabrata.i...@hotmail.comwrote:
Hi Peter,Peter Otten wrote:
SUBHABRATA wrote:
Thanx Peter,
I would change my variables next time I would post.
No, you should use meaningful variable names when you write your code no
matter whether you plan to post it or not.
Good You are teaching me something good in life. Thanx.
And obviously,
thanx for your solution. I am reviewing it, I was also trying out some
solutions.
You misunderstood. I did not modify your code other than changing the
variable names. My hope was that with this modification any errors sprang
to you eye...
I was seeing that.
I am almost near the solution. You can also try some hands if you
feel.
Best Regards,
Subhabrata.
Peter
A couple more things on variable naming and coding style:
- You used "a{digit}" to name variables of different types (a4 was an
int, a2 was a list and the rest were strings). Remember C, where i, j,
k are indices, p, q, r are pointers, s, t are strings and x, y, z are
integers. For unimportant variables, you can skip long descriptive
names, so long you don't use a confusing one.
- You violated your own naming conventions. Why did you choose to use
s to name that last string? Use descriptive names and stick to your
own style.
- You use whitespace weirdly (like in a4>-1 or a4=a3.find).
Try reading PEP8 ( http://www.python.org/dev/peps/pep-0008/), the Style
Guide for Python Code.
As for your code, you need to find where it is that missing_word and
first_char are being updated, and assign to s before that happens.
SUBHABRATA wrote:
Sorry if I didn't say that.
The input is a string "Petrol Helium Heaven Sky"
Now, in a3 it is "God Goddess Heaven Sky" is there,
...I was looking for an output of "H S Petrol Helium"
Meaningful names, splitting the target string, and using 'in' makes the
code much easier.
inwords = "Petrol Helium Heaven Sky".split()
targets = "God Goddess Heaven Sky".split()
found = []
not_found = []
for word in inwords:
if word in targets:
found.append(word[0])
else:
not_found.append(word)
found.extend(not_found)
print(' '.join(found)) # 3.0
#prints the requested
H S Petrol Helium
On Jul 18, 11:42 pm, ptn <tn.pa...@gmail.comwrote:
[snip]
Remember C, where i, j,
k are indices, p, q, r are pointers, s, t are strings and x, y, z are
integers.
Only by convention (even-K&R-v1 C required explicit declarations
almost everywhere), and x etc being used for integers is news to
me ... perhaps you were thinking of m and n.
The only language I remember that had implicit typing was FORTRAN (GOD
is real, but JESUS is an integer).
On Jul 18, 6:43*pm, John Machin <sjmac...@lexicon.netwrote:
On Jul 18, 11:42 pm, ptn <tn.pa...@gmail.comwrote:
[snip]
*Remember C, where i, j,
k are indices, p, q, r are pointers, s, t are strings and x, y, z are
integers.
Only by convention (even-K&R-v1 C required explicit declarations
almost everywhere), and x etc being used for integers is news to
me ... perhaps you were thinking of m and n.
The only language I remember that had implicit typing was FORTRAN (GOD
is real, but JESUS is an integer).
Yes, I meant by convention.
x is the first name that comes to mind when declaring an unimportant
int. Perhaps it's just me.
On Jul 19, 6:34*am, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
On Fri, 18 Jul 2008 16:43:35 -0700 (PDT), John Machin
<sjmac...@lexicon.netdeclaimed the following in comp.lang.python:
The only language I remember that had implicit typing was FORTRAN (GOD
is real, but JESUS is an integer).
Hadn't seen that one before -- maybe because I learned FORTRAN IV at a
college in the middle of west Michigan; I think half the population was
one step away from turning Amish <G>
I learned it by the word: Indian -- implicit integers began at I, and
ended with N.
You could've just used the first 2 letters of 'integer'! :-)
Thanx Terry it worked, I was thinking if input_string could be
searched from given_string and replaced in the input_string but your
one is smarter.
And Peter, thanx for trying to teach conventions. But if I write
explicit comments, and carry on using my own variables( I can use
anything as they are variables:-) ) according to my own ease isn't
that good?
Best Regards,
Subhabrata.
MRAB wrote:
On Jul 19, 6:34�am, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
On Fri, 18 Jul 2008 16:43:35 -0700 (PDT), John Machin
<sjmac...@lexicon.netdeclaimed the following in comp.lang.python:
The only language I remember that had implicit typing was FORTRAN (GOD
is real, but JESUS is an integer).
Hadn't seen that one before -- maybe because I learned FORTRAN IV at a
college in the middle of west Michigan; I think half the population was
one step away from turning Amish <G>
I learned it by the word: Indian -- implicit integers began at I, and
ended with N.
You could've just used the first 2 letters of 'integer'! :-)
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Carlos Ribeiro |
last post by:
As a side track of my latest investigations, I began to rely heavily
on generators for some stuff where I would previsouly use a more
conventional approach. Whenever I need to process a list, I'm...
|
by: Alex |
last post by:
Hi,
I need to form a query where i can add some columns based on the result.
Table A
ColA, ColB
----------
1 A
2 B
|
by: Paulo Jan |
last post by:
Hi all:
Let's say I'm designing a database (Postgres 7.3) with a list of all
email accounts in a certain server:
CREATE TABLE emails (
clienteid INT4,
direccion VARCHAR(512) PRIMARY KEY,...
|
by: Riley DeWiley |
last post by:
I have a programming problem in OLEDB and C++ that seems to be pointing me
toward using layered views and hierarchical rowsets. However, I am uncertain
of the precise implementation and need...
|
by: Madison Kelly |
last post by:
Hi all,
I am new to the list and I didn't want to seem rude at all so I
wanted to ask if this was okay first.
I have a program I have written in perl which uses a postgresSQL
database as the...
|
by: Howard |
last post by:
I need to write a web page that outputs a table from database. ( i want to
write my own code, don't want to use the built-in control)
I came up with two ways of doing this (i use c# 2.0)
1....
|
by: lee |
last post by:
Hi
This is a dumb question as I know it's fairly easy but I cant seem to
find an example after two hours of searching.
In a stored procedure I'm trying to build up a string eg,
(the...
|
by: Nicholas Parsons |
last post by:
Howdy Folks,
I was just playing around in IDLE at the interactive prompt and typed
in dir({}) for the fun of it. I was quite surprised to see a pop
method defined there. I mean is that a...
|
by: jehugaleahsa |
last post by:
I have some code that looks like this:
int customerIds = { 1, 2, 3, 4, 5, 6, 7, 8 };
List<Threadthreads = new List<Threads>();
foreach (int customerId in customerIds)
{
Thread thread = new...
|
by: Thomas Troeger |
last post by:
Hi,
Sorry I've posted a similar question some weeks ago, but I got no
answers. I want to embed a Python application on a device with limited
resources, esp. storage limitations. Is there a way...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |