Jump to content
  • Advertisement
Sign in to follow this  
Calcious

What is wrong with my Python...

This topic is 985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

magicians = ["Alice", "David", "Carolina"]

for magicians in magicians:
		print(magicians)
		
for magicians in magicians:
		print(magicians.title() + ", that was a great trick!")

I do this ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 

I get this as my output... 

 

Alice

David
Carolina
C, that was a great trick! 
A, that was a great trick!
R, that was a great trick!
O, that was a great trick!
L, that was a great trick!
I, that was a great trick!
N, that was a great trick!
A, that was a great trick!
 
 

Share this post


Link to post
Share on other sites
Advertisement

I don't really know Python, but I would guess that it's a variable scope issue.

 

My guess as to how you can fix it -- rename the variable names in the for loops.

Even if that isn't the issue, I would personally refrain from having identical names for the variable describing each separate magician and the collection of magicians.

 

E.g. try

 

for magician1 in magicians

 print(magician1)

 

for magician2 in magicians

 print (magician2.title() + ", that was a great trick!")

---

EDIT: Seraph ninja.

Edited by Lactose!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!