[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can anyone help me with this Python program? >have a bunch

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 2

File: isla2.jpg (213KB, 1360x765px) Image search: [Google]
isla2.jpg
213KB, 1360x765px
Can anyone help me with this Python program?

>have a bunch of names
>need first char of each name to be printed on same line in uppercase

Code:
#!/usr/bin/env python

def get_upper(string):
new_string = ''
for char in string:
new_string = new_string + char.upper()
if new_string:
return new_string
else:
return False

def get_lower(string):
new_string = ''
for char in string:
new_string = new_string + char.lower()
if new_string:
return new_string
else:
return False

def get_name(name):
return name

def get_first_letter(name):
first = None
for letter in name:
if get_lower(letter) == get_lower(name[0]):
first = get_lower(letter)
if first:
return first
else:
return False

def operations():
name_list = []

counter = 1

while counter < 8:
if counter == 1:
name_list.append("get_name('terry')")
elif counter == 2:
name_list.append("get_name('rose')")
elif counter == 3:
name_list.append("get_name('opie')")
elif counter == 4:
name_list.append("get_name('luke')")
elif counter == 5:
name_list.append("get_name('larry')")
elif counter == 6:
name_list.append("get_name('eddie')")
elif counter == 7:
name_list.append("get_name('derrik')")

counter = counter + 1

if counter > 7:
break

for name_func in name_list:
name = eval(name_func)
first_letter = get_first_letter(name)
print get_upper(first_letter),

operation()


Getting this error though:
Traceback (most recent call last):
File "lol.py", line 65, in <module>
operation()
NameError: name 'operation' is not defined


operation() clearly is defined though, so what's wrong?
>>
You defined operations and you are calling operation
>>
OPERATIONS

not OPERATION
>>
>>52401027
Nice code.
>>
Long code is boring
>>
>>52401027
>python2
>unironically using eval

iunno bout this fàm
>>
>>52401027
your code is pathetic, try again
>>
>/g/
>CS101 homework hotline
>>
>>52401027
your code is shit
>>
Thanks guys finally got the right output
T R O L L E D
>>
>>52402013
>>>reddit
>>
>>52401027
Python "programmers", everybody.
>>
>operations vs operation
made me kek, thanks op
Thread posts: 13
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.