[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 / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
Can anyone help me with this Python program?
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

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

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



[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 / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

[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 / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | 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.
This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.