Help with code pls

How do I get some code to run every time the player gives a command?


https://replit.com/@ArieSabbah/new-repl#main.py

code snippet

Can you please elaborate? What do you mean by “the player gives a command”? A discord bot? A telegram bot?

ah I see, so you want your code to be user guided? use input!

choice = input("hello, please select a name: ")

so this allows the user to enter something until the user presses enter so, say the user presses:
e d d i e [ENTER] (this is called \n in python!)
the code will get

choice = "eddie" # yay! it can be anything tho

you can use this with conditionals to do things

if ("e" in choice):  # e in name
    print("You have e in your name!")
else: # otherwise
    print("You do not have e in your name")
4 Likes

Why parentheses lol?

4 Likes

oh because I use c++ and stuff and it just looks nicer to me

1 Like

Oh ok thanks :smiley: that’s really helpful :smiley:

please mark it as solved then

1 Like

You can do something like the following.

command = input("> ")
if command == "hi":
  print("Hello world!")
elif command == "meow":
  print("The cat goes meow.")
else:
  print("Invalid command.")

that’s what I said as well :smiley:

1 Like

Oh really? ok :smiley: nice

Also in C it looks like this

if(e in choice){ // e in name
  printf("You have e in your name!");
}

else{ //otherwise
  printf("You do not have e in your name");
}

Thank you

Request

If there is any changes please tell me that

1 Like

yes I know since C++ is a superset of C with classes

BTW you have to do

strchr(choice, 'e') != NULL
3 Likes

What do you mean that?
You can show me that by doing edit my post
Looking forward for your response @bigminiboss

I mean there are no keywords for in in c, you need to use a function to check if a char is in a string

Would you please edit my post

1 Like

your post is not editable by me :sweat_smile:

2 Likes

Can you please give me corrected code?

1 Like

Try this:

repeat = (“y”)
while repeat == (“y”):
    repeat = input(“Do you want to repeat?(y/n)”)

Also, mark the post that you found most helpful as the solution so the topic can close.

1 Like
if(strchr(choice, 'e') != NULL){ // e in name
  printf("You have e in your name!");
}

else{ //otherwise
  printf("You do not have e in your name");
}


3 Likes