[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Can anyone help me with this Python program? >have a bunch
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 13
Thread images: 2
File: isla2.jpg (213 KB, 1360x765) Image search: [Google]
isla2.jpg
213 KB, 1360x765
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 replies: 13
Thread images: 2

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.