Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,205,003 members, 7,990,765 topics. Date: Friday, 01 November 2024 at 12:12 AM

Help Am Stucked - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Am Stucked (1467 Views)

Help, Am In A Dilemma. (2) (3) (4)

(1) (Reply) (Go Down)

Help Am Stucked by Nastydroid(m): 8:56pm On Nov 01, 2014
i just started python so am stucked here

>>> names = ["ayo","tola","snake"]
>>> print(names)
>>> ['ayo', 'tola', 'snake']
>>> names.remove(snake)
>>>print(names)
>>> ['ayo', 'tola']
>>> names.insert(2,"dapo"wink
>>> print(names)
>>>['ayo', 'tola', 'dapo']
>>> for each_item in names:
print(each_item)





















the items are not printing,wat am i doing wrong?
Re: Help Am Stucked by blueyedgeek(m): 9:49pm On Nov 01, 2014
You know python is pretty strict about indentation. Check to make sure your code is well indented. I don't really know much about Python but if what you are trying to do is to loop through an array and print out every item in it, here is how it would be done using javascript


var names = ["ayo"
, "tola", "dapo"];
for(var count = 0; count < names.length; count++){
console.log(names[count]);
}


Now, you might wonder how this is helpful but I am under the assumption that all programming languages at their core follow the same basic principles so using mine, I would infer that your code might not be working because your syntax might be incorrect. You need to use the length of the array in your loop statement (I'm not sure how this is done in python)
and also for the print statement, it should be print(names[each_item]) and not just print(each_item).
Re: Help Am Stucked by Nastydroid(m): 10:23pm On Nov 01, 2014
thanks bro,i will try your hint tomorrow..yea am trying to loop through an array
Re: Help Am Stucked by Nobody: 11:32pm On Nov 01, 2014
Just make sure your indentation is good...that's the normal syntax
BTW are you using an IDE at all cos IDEs are supposed to help auto indent your code normally.
Re: Help Am Stucked by Nastydroid(m): 11:54pm On Nov 01, 2014
olucurious:
Just make sure your indentation is good...that's the normal syntax
BTW are you using an IDE at all cos IDEs are supposed to help auto indent your code normally.
am use an IDE but it is not doing the auto indent stuff,but it do show me the error line.in this case no error was shown it just couldn't print
Re: Help Am Stucked by aslan(m): 12:03am On Nov 02, 2014
i work with python so try this:
>>>for x in names:
print(x)

don't forget to use the correct indentation rule which is four spaces.
Re: Help Am Stucked by Nastydroid(m): 12:08am On Nov 02, 2014
aslan:
i work with python so try this:
>>>for x in names:
print(x)

don't forget to use the correct indentation rule which is four spaces.
alrite bro thanks
>>> for ayo in names:
print(ayo)

wat if i want to print everything at once
Re: Help Am Stucked by aslan(m): 12:22am On Nov 02, 2014
the code i gave you is what you will use to print everything. don't modify the code. if you want to print out one of the items in names, use python's slice notation like this: name[0] will print 'ayo' name[1] will print 'tola' and name[2] will print 'dapo'
Re: Help Am Stucked by dhtml(m): 8:30am On Nov 02, 2014
Trollin'
Re: Help Am Stucked by Nastydroid(m): 5:03pm On Nov 03, 2014
aslan:
i work with python so try this:
>>>for x in names:
print(x)

don't forget to use the correct indentation rule which is four spaces.
hey bro,am having problem with my module it is not working,can you explain how to make it work.whenever I search for it will reply wit no module found



>>> def print_lol(the_list):
For each_item in the_list:
If isinstance(each_item, list):
Print_lol(each_item)
Else:
Print(each_item)



That is the module I saved it as nester.py
Cc aslan and ajibel etc
Re: Help Am Stucked by Ajibel(m): 10:36am On Nov 04, 2014
for name in enumerate(names):
print(name)

OR

[name for name in names] #list comprehension

Does that solve it
Re: Help Am Stucked by Ajibel(m): 10:44am On Nov 04, 2014
Do it this way, dont indent=>

>>> names = ['amu', 'otu', 'oko']
>>> for name in names: print(name) #must be on one line
Re: Help Am Stucked by Nastydroid(m): 1:54pm On Nov 04, 2014
Ajibel:
Do it this way, dont indent=>

>>> names = ['amu', 'otu', 'oko']
>>> for name in names: print(name) #must be on one line
i want to print it with the function >>> print_lol are u on whatsapp bro
Re: Help Am Stucked by Nastydroid(m): 1:55pm On Nov 04, 2014
Ajibel:
Do it this way, dont indent=>

>>> names = ['amu', 'otu', 'oko']
>>> for name in names: print(name) #must be on one line
i have solved this already bro...having problem with module
Re: Help Am Stucked by Ajibel(m): 4:12pm On Nov 04, 2014
Nastydroid:
i have solved this already bro...having problem with module

Module That's unclear please explain further.
Re: Help Am Stucked by Nastydroid(m): 8:20pm On Nov 04, 2014
Ajibel:


Module That's unclear please explain further.
turning a function into a module i posted d code above
Re: Help Am Stucked by Ajibel(m): 8:51am On Nov 05, 2014
Nastydroid:
turning a function into a module i posted d code above

Geez. Okay.
Open a new window and type this:

def func(*arg): print(arg)

Save the file as test.py.

Then hit on F5

A python shell would be opened

Then type:
func('ayo', 'bola', 'cassey')

Then hit enter

And you get your result
Re: Help Am Stucked by Nastydroid(m): 11:49pm On Nov 06, 2014
Ajibel:


Geez. Okay.
Open a new window and type this:

def func(*arg): print(arg)

Save the file as test.py.

Then hit on F5

A python shell would be opened

Then type:
func('ayo', 'bola', 'cassey')

Then hit enter

And you get your result
thanks bro

(1) (Reply)

Simplex Media Converter download link available ! / Google To Bring Free Wifi To The World / When Your Brain Throws Stackoverflow Error - Debug This JAVA Code If You Can

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.