Python Forum
"Travis" guest list name checker (Ziyad Yehia Udemy course)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Travis" guest list name checker (Ziyad Yehia Udemy course)
#3
Thank you @jefsummers for your advice.

(Aug-23-2019, 01:04 AM)jefsummers Wrote: So, what type does main() return?

Right now the main() function returns a variable as (placeholder) which represents two other variables: guest_list and user_name. When I call the main() function under the __name__ guard, I am assigning it to two variables (which I gather is technically impossible because a variable can only represent a single other variable and not two). So this is a major problem.

(Aug-23-2019, 01:04 AM)jefsummers Wrote: That is the type assigned to placeholder in the dunder main.

I’m not sure what you mean by the dunder main.

(Aug-23-2019, 01:04 AM)jefsummers Wrote: What type does the check() function require as an argument?

The check() function requires two variables as its argument: both guest_list and user_name which I thought I had assigned together as placeholder. In my next iteration of this script (copied below), at line 13 where the check() function is defined, I have swapped out placeholder and am now using guest_list and user_name because these are the two required arguments according to Name Error in the trace back.

Here are the changes I have made to my script since my previous post:
  1. At line 10 I return just guest_list, user_name without brackets because previously with brackets, it returns a tuple. I don’t want a tuple.
  2. At line 13 where I define the check function, instead of placeholder I pass in guest_list, user_name because this is what the function actually needs
  3. Under the name guard at the bottom, I keep placeholder assigned to main() but when I call check() I include the two required parameters: guest_list, user_name

Quote:Note that you can't determine that by the type of placeholder from main, and using the same name for the argument as the variable in main can be confusing (and therefore recommend avoiding, it comes back to bite you - if you had used a different name the problem would be obvious).

I am struggling to manage these variable assignments and pass them as arguments.

I feel like I have made a valiant attempt here to accomplish what I set out to achieve and I have come pretty close. The solution I need is so trivial and minor, I think I am at the point where I am ready to see the full solution from a forum member like @jefsummers or someone else demonstrating how to manage functions and variable assignments in the context of my script.

Here is my slightly altered script that I am working with now with the three changes noted above:

#!/usr/bin/env python3
# This fourth iteration of this script splits attempts to resolve the Type + Name Errors

def main():
    """
    Initializes the two primary variables and returns them for future use
    """
    guest_list = ["Justin Trudeau", "Joseph Stalin", "Caesar", "Nero",]
    user_name = input("What is your name? Please spell it in full! >>  \n")
    return guest_list, user_name


def check(guest_list, user_name):
    """
    Verifies the user name input and determines if in guest list
    """
    print(guest_list, user_name)
    if user_name in guest_list:
        print(f"Welcome, {user_name}!")
    if user_name not in guest_list:
        print(f"Hi {user_name}, but unfortunately you are not in the guest list.")
        include_proposition = input("Would you like to join us anyways? Please enter a Yes or a No >> \n")
        if include_proposition == ("Yes", "Y", "y"):
            guest_list.append(user_name)
            print(f"Thanks, {user_name}! You've been added. Please enter.")
        if include_proposition == ("No", "N", "n"):
            print("OK! Have a good night then, my friend!")
        else:
            print("Sorry, I didn't get that. Please enter your selection again")


if __name__ == "__main__":
    placeholder = main()
    check(guest_list, user_name)
Even with these changes, here is the NameError still showing:

Quote:$ python script4.py
What is your name? Please spell it in full! >>
west
Traceback (most recent call last):
File "script4.py", line 34, in <module>
check(guest_list, user_name)
NameError: name 'guest_list' is not defined
Reply


Messages In This Thread
RE: "Travis" guest list name checker (Ziyad Yehia Udemy course) - by Drone4four - Aug-23-2019, 06:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating guest list manager nickster11 1 2,916 Feb-08-2021, 02:44 PM
Last Post: deanhystad
  Password Checker Assignment mcostello 1 5,183 Nov-14-2020, 07:54 AM
Last Post: DPaul
  Palindrome checker case sensive edwdas 3 2,718 Nov-07-2019, 05:57 PM
Last Post: nilamo
  Syntax checker BZA 4 3,261 May-16-2019, 06:40 PM
Last Post: BZA
  Spell Checker Liquid_Ocelot 1 3,240 May-07-2017, 11:28 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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