Variable is not accessed in Pylance


For some reason, I am receiving an error on VSCode that says the specific variable is not accessed Pylance and each variable says the same thing,

Am I missing something simple?

full code below:

score = 0   

def gen1_questions():
    q1 = input("Question 1. What is the rarest M&M color? ")
    q2 = input(
        "Question 2. In a website browser address bar, what does “www” stand for? ")
    q3 = input(
        "Question 3. Which country consumes the most chocolate per capita? ")
    q4 = input("Question 4. Who was the very first American Idol winner? ")
    q5 = input(
        "Question 5. What is the tiny piece at the end of a shoelace called? ")
    q6 = input("Question 6. How many weeks are in a year? ")
    q7 = input("Question 7. Which animal can be seen on the Porsche logo? ")
    q8 = input("Question 8. Muhammad Ali was well-known in which sport? ")
    q9 = input("Question 9. What is the lowest army rank of a US soldier? ")
    q10 = input(
        "Question 10. What is often seen as the smallest unit of memory greater than a byte? ")

def gen2_questions():
    q1 = input(
        "Question 1. Which is one of two U.S. states does not observe Daylight Saving Time? ")
    q2 = input(
        "Question 2. Michael Jordan won how many NBA titles with the Chicago Bulls? ")
    q3 = input("Question 3. What color eyes do most humans have? ")
    q4 = input("Question 4. What is the hardest rock on earth? ")
    q5 = input("Question 5. What is the solar systems hottest planet? ")
    q6 = input("Question 6. What is the fastest-flying bird in the world? ")
    q7 = input(
        "Question 7. Who was the first woman to have four country albums reach No. 1 on the Billboard 200? ")
    q8 = input(
        "Question 8. What is illegal for a single lady to do in Florida solely on Sundays? ")
    q9 = input("Question 9. Which is the Worlds Largest Ocean? ")
    q10 = input(
        "Question 10. What type of exercise is best for getting the blood flowing? ")

>Solution :

If that’s the only code you have then, yes, you set (for example) q1 to a value but never use it after that.

If you’ve failed to show us code outside of those functions that uses q1, it still is not being used.

That’s because, if you assign to a variable (like q1 = 42) within a function and that variable is not explicitly marked global, it will be a new local variable within the function, not one already existing in a containing namespace.

Leave a Reply Cancel reply