Jump to content

I'm stuck again, like always

 

This is the code i am using, it only seems to print the first name, im confused

 

n = ["Michael", "Lieberman"]
def join_strings(words):
    result = ""
    for item in range(len(words)):
        result += words[item]
        return result
print join_strings(n)

 

post-17790-0-53994400-1395836383_thumb.p

Desktop - Corsair 300r i7 4770k H100i MSI 780ti 16GB Vengeance Pro 2400mhz Crucial MX100 512gb Samsung Evo 250gb 2 TB WD Green, AOC Q2770PQU 1440p 27" monitor Laptop Clevo W110er - 11.6" 768p, i5 3230m, 650m GT 2gb, OCZ vertex 4 256gb,  4gb ram, Server: Fractal Define Mini, MSI Z78-G43, Intel G3220, 8GB Corsair Vengeance, 4x 3tb WD Reds in Raid 10, Phone Oppo Reno 10x 256gb , Camera Sony A7iii

Link to comment
https://linustechtips.com/topic/131938-why-do-i-suck-at-python-help-me/
Share on other sites

Link to post
Share on other sites

Put the return statement outside of the for loop.

n = ["Michael", "Lieberman"]def join_strings(words):    result = ""    for item in range(len(words)):        result += words[item]    return resultprint join_strings(n)
Link to post
Share on other sites

take the return statement out of the for loop. 

CPU: Intel Core i5 2500K | Case: Bitfenix Prodigy | Motherboard: GA-H61N-USB3 | RAM: Corsair 8GB 1333 MHz Video CardEVGA GTX 660 Superclocked 2GB DDR5

Power Supply: Corsair CX 430 | SSD: Samsung 840 120GB | HDD: 2X Seagate Barracuda 500GB 7200rpm | Monitor Asus PB238Q & Asus PB278Q

Mouse: Lenovo N50 | Keyboard: Apple Pro Keyboard | Operating Systems: Hackintosh OS X 10.8.5 & Windows 8.1

Link to post
Share on other sites

Oh yeah, how stupid of me :) i just had to put it on the line below ><

 

I keep messing up on little things like that, Ill get the hang of it im sure

Desktop - Corsair 300r i7 4770k H100i MSI 780ti 16GB Vengeance Pro 2400mhz Crucial MX100 512gb Samsung Evo 250gb 2 TB WD Green, AOC Q2770PQU 1440p 27" monitor Laptop Clevo W110er - 11.6" 768p, i5 3230m, 650m GT 2gb, OCZ vertex 4 256gb,  4gb ram, Server: Fractal Define Mini, MSI Z78-G43, Intel G3220, 8GB Corsair Vengeance, 4x 3tb WD Reds in Raid 10, Phone Oppo Reno 10x 256gb , Camera Sony A7iii

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×