How to write inline if statement for print?
I need to print some stuff only when a boolean variable is set to True. So, after looking at this, I tried with a simple example:
I need to print some stuff only when a boolean variable is set to True. So, after looking at this, I tried with a simple example:
I got a function online to help me with my current project and it had semicolons on some of the lines. I was wondering why? Is it to break the function?
If I enter any value less than 24, it does print the “You will be old…” statement. If I enter any value greater than 24 (ONLY up to 99), it prints the “you are old” statement.
In JavaScript, one could do this: if (integer > 3 && integer < 34){ document.write("Something") } Is this possible in Python? Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the … Read more
I know how to use both for loops and if statements on separate lines, such as:
def isBig(x): if x > 4: return 'apple' else: return 'orange' This works: if isBig(y): return isBig(y) This does NOT work: if fruit = isBig(y): return fruit Why doesn’t the 2nd one work!? I want a 1-liner. Except, the 1st one will call the function TWICE. How to make it 1 liner, without calling the … Read more
I’m trying to get an if statement to trigger from more than one condition without rewriting the statement multiple times with different triggers. e.g.: if user_input == "look": print description if user_input == "look around": print description How would you condense those into one statement? I’ve tried using ‘or’ and it caused any raw_input at … Read more