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 ..

16th May 2020, 7:09 AM
Alapottra Chakma
Alapottra Chakma - avatar
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?
16th May 2020, 8:57 AM
Manish
Manish - avatar
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.
16th May 2020, 7:33 AM
Manish
Manish - avatar
0
i want to print the move funcion if user inputs "move" string
16th May 2020, 7:37 AM
Alapottra Chakma
Alapottra Chakma - avatar
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
16th May 2020, 7:50 AM
Alapottra Chakma
Alapottra Chakma - avatar
0
I want*
16th May 2020, 7:50 AM
Alapottra Chakma
Alapottra Chakma - avatar
0
yes.. i wonder why mine showed an unreachable error..
16th May 2020, 9:13 AM
Alapottra Chakma
Alapottra Chakma - avatar
0
thanks anyways
16th May 2020, 9:14 AM
Alapottra Chakma
Alapottra Chakma - avatar