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
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")
Why parentheses lol?
oh because I use c++ and stuff and it just looks nicer to me
Oh ok thanks that’s really helpful
please mark it as solved then
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
Oh really? ok 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
If there is any changes please tell me that
yes I know since C++ is a superset of C with classes
BTW you have to do
strchr(choice, 'e') != NULL
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
your post is not editable by me
Can you please give me corrected code?
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.
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");
}