0
help with my code in python (beginner)
code : class Person: def __init__(self, name): self.name = name def move (self): print (f" {self.name} " "moved a bit" ) bob = Person ("bob") talk = input(">") == "move" bob.move() Question : here i wanted to execute the move function inside the the class whenever the user enters "move" as a input ..i know it has to do something with if statement but couldn't really figure it out where to put it ..it shows a unreachable error if i use the if statement.. and problem in this current code is that even if i type anything other then move i still get the same output ..
7 Answers
+ 1
class Person:
def __init__(self, name):
self.name = name
def move (self):
print (f" {self.name} moved a bit" )
bob = Person ("bob")
command = input("Enter move to move")
if command.lower() == "move":
bob.move()
# Like this?
0
class Person:
def __init__(self, name):
self.name = name
def move (self):
print (f" {self.name} moved a bit" )
bob = Person ("bob")
bob.move()
# compare code...
# error in text formatting while printing
# what you wanted to do after making instance...
# make me clear about this.
0
i want to print the move funcion if user inputs "move" string
0
its like the want the user to have to control over which functions in the "class= Person" will be executed or done .. by him giving commands on the input
0
I want*
0
yes.. i wonder why mine showed an unreachable error..
0
thanks anyways



