Python Forum
problem about 'if' and 'for' from a python beginner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem about 'if' and 'for' from a python beginner
#1
The python code is as below:
curren_accounts=['amy','ADA','eric','tim','jasmin']
new_accounts=['torge','tom','ada','ace','amanda']
for new_account in new_accounts:
	for curren_account in curren_accounts:
		if new_account.title() == curren_account.title():
			print('"'+new_account+'"'+' is already used, please find a new name.')
			new_accounts.remove(new_account)
			print(new_accounts)
	if new_account in new_accounts:
		print('"'+new_account+'"'' is not be used yet.')
the result is as below:
"torge" is not be used yet.
"tom" is not be used yet.
"ada" is already used, please find a new name.
['torge', 'tom', 'ace', 'amanda']
"amanda" is not be used yet.

So the question is why 'ace' in the new_account is not processed in the result.
Many thanks!
Reply


Messages In This Thread
problem about 'if' and 'for' from a python beginner - by yzjnpu - Jun-26-2018, 03:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  small beginner problem FelixReiter 2 1,872 Nov-17-2020, 03:26 PM
Last Post: FelixReiter
  Beginner having Syntax Error problem RyanHo 3 2,391 Sep-10-2020, 08:33 AM
Last Post: cnull
  Beginner, my recursion returns None, and related problem zpacemanzpiff 2 1,816 Jul-02-2020, 04:25 AM
Last Post: zpacemanzpiff
  Beginner problem, replace function with for loop Motley_Cow 9 4,657 Sep-13-2019, 06:24 AM
Last Post: Motley_Cow
  Beginner problem in python script Cedmo 3 2,794 Jul-04-2019, 08:22 PM
Last Post: Cedmo
  Beginner Problem python 2.7 Jonathan_levy 2 2,696 Jul-04-2018, 08:46 PM
Last Post: ichabod801
  Beginner Problem python 2.7 Jonathan_levy 2 2,732 Jul-03-2018, 11:58 AM
Last Post: gruntfutuk
  Beginner. Calculator problem ¯\_(ツ)_/¯ stykus1992 0 2,356 Feb-15-2018, 11:01 AM
Last Post: stykus1992

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020