• Register
1 vote
13 views

Problem:

I am new in python programming an I have been learning for this some days. As a newbee I am still learning and and I am cofused about some things. My question is “In an if/else statement, if the boolean expression is always false?”

 

10 7 2
6,060 points

1 Answer

0 votes

Answer:

A boolean or bool is a data type that has two possible values: it is either true, or false.
Very often when you write code, you want to perform different actions for different decisions. 
You can use conditional statements in your code to do this. 
Use if to specify a block of code to be executed, if a specified condition is true. Use else to specify a block of code to be executed.
A Boolean variable has only two possible values: true or false. It is common to use Booleans with control statements to determine the flow of a program. In this example, when the boolean value "x" is true, vertical black lines are drawn and when the boolean value "x" is false, horizontal gray lines are drawn

If you want to know more you can go to:

http://openbookproject.net/thinkcs/python/english3e/conditionals.html

or visit:

https://www.khanacademy.org/computing/ap-computer-science-principles/programming-101/boolean-logic/a/conditionals-with-if-else-and-booleans

 

11 6 4
34,950 points

Related questions

1 vote
1 answer 26 views
26 views
Problem: Let me put it as sim as I can. I have an if statement in my code and it returns a value. Since IF is a boolean statement it should return value whether it’s true or false. So, in my program when a method tests an argument and returns a true or ... as a parameter in a different method inside an IF statement. How should I do that? Any kind of help is appreciated by my side. Thanks.
asked Mar 17 Gavin 15.3k points
2 votes
1 answer 36 views
36 views
Problem: Hello I am a new learner of programming. I’ve started with Java programming language. I am learning step by step. I stuck somewhere in an if-else statement. I’ve written a basic program for practice purpose but it’s not running. I am unable to figure out the ... ==0) System.out.println("a is not present\n"); System.out.println("It is outside of the if-else-if"); } }
asked Mar 26 Gavin 15.3k points
0 votes
1 answer 113 views
113 views
Problem: I am new in programming and stuck in a query, can anyone guide me? Write an expression that evaluates to True if the str associated with s starts with "p"?
asked Feb 17 maddi86 5.4k points
0 votes
1 answer 79 views
79 views
Problem : I am facing following error with the below query in SQL Server 2012. An expression of non-boolean type specified in a context where a condition is expected, near 'RETURN'. SQL Query: CREATE FUNCTION [dbo].[GetMYPMResources](@UserResourceNo ... JOIN JobTask t ON t.JobTaskNo = m.JobTaskNo WHERE t.TaskManagerNo = @UserResourceNo OR t.AlternateTaskManagerNo = @UserResourceNo ) RETURN END
asked Dec 4, 2019 alecxe 7.5k points
1 vote
1 answer 9 views
9 views
Problem: I understand the basic flow of an if-else statement very well. Today I was reading somewhere that it is possible to set a ternary condition using the if-else statement. Let&rsquo;s say, I have a set of conditions like below: if i > 100: x = 2 elif i < 100: x = 1 else: x = 0 How can I put all the conditions and statements within a single line? Could you please help me out?
asked May 31 adamSw 11.3k points