Home » Python » python – I have to output two different messages if "x" is a certain value. what is the best way to do this?-Exceptionshub

python – I have to output two different messages if "x" is a certain value. what is the best way to do this?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:
x=50
print(("Hi, your percentage is"if x>100else"Your percentage is")+" %.f%%"%x)

This prints out “Your percentage is 50%”

Which is what I want, but is there a better and more simpler way to do this that takes a lesser amount of codes/lines? Can “x” somehow be combined into the print statement? Assume x can change values, I just inserted 50 for demonstration.

How to&Answers: