Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
How do I make this line of code shorter?
–1
vote
asked
Oct 31, 2018
by
Ender
(
120
points)
if x == "hello":
print("great")
elif x == "hi":
print("great")
I want to make the if hi and if hello shorter into if hi and hello
python
Please
log in
or register to answer this question.
4 Answers
0
votes
answered
Oct 31, 2018
by
Kevin Sweny
(
190
points)
If you wanted the logic to be if x == hi, OR hello
You would use if ((x == "hello") || (x x == "hi")), the operator for OR is ||
commented
Dec 11, 2018
by
Tomas Z
(
180
points)
operator || is not in python, but you can use or keyword instead.
Please
log in
or register to add a comment.
+2
votes
answered
Nov 3, 2018
by
Prabhat Mishra
if(x=='hello' or x=='hi'):
print("great")
Please
log in
or register to add a comment.
+4
votes
answered
Jan 4, 2019
by
Raphael SCHMITZ-DU MONT
(
220
points)
another way would be
if x in ['hello', 'hi']:
print('great')
Please
log in
or register to add a comment.
0
votes
answered
Jun 13, 2021
by
ITSME
(
760
points)
You can use or operator
if (x == "hi" or "hello"):
print ("Great")
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...