Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Begginer coding problem
#1
Hello,

Im pretty new to python and programming and I need some help. I need to check if user name is already in usage by another one. That was good and I dealt with it pretty fast. But then I found that if new user name is "Mark" and current user name is "MARK" It says that it's all good and this user doesn't have to change the name, but that's wrong. How can I make it to say that user name needs to be changed? I just need to make sure that letter size doesn't matter in comparing these two. I'm really thankful for all help!

That's my code so far:

current_users = ['alex', 'zuzia', 'zoie', 'maciej', 'wiktor', 'MARK']
new_users = ['alex', 'monika', 'pawel', 'henryk', 'adam', 'Mark']

for new_user in new_users:
	if new_user in current_users:
		print("You need to change users name!")
	else:
		print("You dont have to choose diffrent users name!")
Reply
#2
Hello and welcome to Python and our forums!
Usually this problem is tackled by converting all the strings to lowercase. Python's builtin lower() function is used for that. For example:

current_users = ['alex', 'zuzia', 'zoie', 'maciej', 'wiktor', 'MARK']
new_users = ['alex', 'monika', 'pawel', 'henryk', 'adam', 'Mark']

current_users_lower = [x.lower() for x in current_users]
new_users_lower = [x.lower() for x in new_users]

for new_user in new_users_lower:
    if new_user in current_users_lower:
        print("You need to change users name!")
    else:
        print("You dont have to choose diffrent users name!")
Lines 4 and 5 are list comprehensions, they create a new list with the "formula" provided. I think you can easily decipher how it works.
It is possible to do it without list comprehensions too, but it would be a less elegant solution with loops.
Reply
#3
Thank you so much!

Well, actually i copied it just perfectly, but I don't understand that. I will appreciate you if you would make easier and less elegant form because i'm on too low lever for now.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Armachat coding problem gad969 4 1,311 Mar-12-2023, 03:12 PM
Last Post: gad969
  Coding problem portfolio grade max70990 1 738 Dec-11-2022, 12:30 PM
Last Post: Larz60+
  coding problem from older book teddfirth 3 2,147 Mar-06-2021, 03:51 PM
Last Post: teddfirth
  Begginer problem with turtle Damien_X 1 2,084 Aug-25-2020, 11:23 AM
Last Post: GOTO10
  Someone please help a begginer leonr 3 3,332 Mar-13-2018, 02:35 PM
Last Post: leonr
  IR coding problem DPaul 3 2,774 Jan-09-2018, 08:02 AM
Last Post: DPaul
  new user coding problem mattkrebs 1 3,026 Mar-21-2017, 12:45 PM
Last Post: buran
  Coding problem VISHU 3 4,833 Mar-16-2017, 06:54 AM
Last Post: Larz60+
  Incredibly basic coding problem AndyF 12 8,520 Feb-11-2017, 03:52 PM
Last Post: AndyF

Forum Jump:

User Panel Messages

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