”Statement seems to have no effect” when using While with True & a return for accessing a list

3640 views python
6

I’m a novice coder, trying to execute the below code in Python 3, IDE: Pycharm. For the line containing the code: opt_list[opt_choice] when I hover over that line of code, the message "Statement seems to have no effect" is popping up. When I execute the code, it shows me the Menu, takes the input. However, it just exits after that:

def remove_letter():       # Remove a selected letter from a string
    print("Remove letter")
    return

def num_compare():       # Compare 2 numbers to determine the larger
    print("Number compare")
    return

def print_string():      # Print the previously stored string
    print("Printing the saved String:")
    print(saved_string)
    return

def calculator():      # Basic Calculator(addition, subtraction, multiplication, division)
    print("Calculator")
    return

def accept_and_store():  # Accept and store a string
    print("Accept and store")
    global saved_string
    saved_string = str(input("Input Strings: "))
    return

def main(): # menu goes here
opt_list = [accept_and_store,
calculator,
print_string,
num_compare,
remove_letter]

while True:
print(”SELECT OPTION:”)
print(”1.\tAccept and Store”)
print(”2.\tCalculator”)
print(”3.\tPrint Stored String”)
print(”4.\tNumber Comparision”)
print(”5.\tLetter Remover”)
print(”6.\tQuit”)
opt_choice = int(input(”SELECTION: ”))
opt_choice -= 1
opt_list[opt_choice]

return

main()

Request your help in this regard.

answered question

1 Answer

11

I could see 2 issues.

There is no indentation for the 2 functions. Other is the Double quotes for the print function. It seems to be a different character. ” instead of " below the While function.

def main(): # menu goes here
   opt_list = [accept_and_store,
               calculator,
               print_string,
               num_compare,
               remove_letter]

   while True:
     print("SELECT OPTION:")
     print("1.\tAccept and Store")
     print("2.\tCalculator")
     print("3.\tPrint Stored String")
     print("4.\tNumber Comparision")
     print("5.\tLetter Remover")
     print("6.\tQuit")
     opt_choice = int(input("SELECTION: "))
     opt_choice -= 1
     opt_list[opt_choice]

posted this

Have an answer?

JD

Please login first before posting an answer.