0

i'm a python fresher. I have a problem and want to ask for the answers. there is my class :

class DoSomethingWithList :

    def inputList(self, parameter_list):
       ...

    def deleteSomething(self):
       ...

and the rest of

temp = 0

while temp == 0 :

selection = input('input selection: ')
list1 = DoSomethingWithList()

if selection == 1 :  
    RangeOfList = int(input('input range of list : '))
    list1.inputList(RangeOfList) # this is not executed
elif selection == 2 :
    list1.deleteSomething()      # and this too
else : 
    temp = 1

this code looped forever. list1 objects aren't performed. I cant see the problem here.Sorry for my bad English

Non Non
  • 11
  • 4

1 Answers1

2

input function reads a string rather than a number. you should change the if conditional from 'selection == 1' to 'selection == "1"' like highlighted below

selection = input('input selection: ')
list1 = DoSomethingWithList()

if selection == "1" : 
  RangeOfList = int(input('input range of list : '))
  list1.inputList(RangeOfList) # this is not executed
elif **selection == "2" :**
   list1.deleteSomething()      # and this too
else : 
   temp = 1
BobLoblaw
  • 1,873
  • 4
  • 18
  • 27