Write a small program that takes in two numbers from the user. Using an if statement and an else statement, compare them and tell the user which is the bigger number. Also, consider what to output if the numbers are the same.

Test your program in REPL.it, and then copy it to your Coding Log.

(If you’re up for an extra challenge, try extending the program to accept three numbers and find the biggest number!)

And only give me a good answer not some random letters plz. ty

Answers

Answer 1

Answer:

4. Conditionals

4.1. The modulus operator

The modulus operator works on integers (and integer expressions) and yields the remainder when the first operand is divided by the second. In Python, the modulus operator is a percent sign (%). The syntax is the same as for other operators:

>>> quotient = 7 / 3

>>> print quotient

2

>>> remainder = 7 % 3

>>> print remainder

1

So 7 divided by 3 is 2 with 1 left over.

The modulus operator turns out to be surprisingly useful. For example, you can check whether one number is divisible by another—if x % y is zero, then x is divisible by y.

Also, you can extract the right-most digit or digits from a number. For example, x % 10 yields the right-most digit of x (in base 10). Similarly x % 100 yields the last two digits.

4.2. Boolean values and expressions

The Python type for storing true and false values is called bool, named after the British mathematician, George Boole. George Boole created Boolean algebra, which is the basis of all modern computer arithmetic.

There are only two boolean values: True and False. Capitalization is important, since true and false are not boolean values.

>>> type(True)

<type 'bool'>

>>> type(true)

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>

NameError: name 'true' is not defined

A boolean expression is an expression that evaluates to a boolean value. The operator == compares two values and produces a boolean value:

>>> 5 == 5

True

>>> 5 == 6

False

In the first statement, the two operands are equal, so the expression evaluates to True; in the second statement, 5 is not equal to 6, so we get False.

The == operator is one of the comparison operators; the others are:

x != y               # x is not equal to y

x > y                # x is greater than y

x < y                # x is less than y

x >= y               # x is greater than or equal to y

x <= y               # x is less than or equal to y

Although these operations are probably familiar to you, the Python symbols are different from the mathematical symbols. A common error is to use a single equal sign (=) instead of a double equal sign (==). Remember that = is an assignment operator and == is a comparison operator. Also, there is no such thing as =< or =>.

4.3. Logical operators

There are three logical operators: and, or, and not. The semantics (meaning) of these operators is similar to their meaning in English. For example, x > 0 and x < 10 is true only if x is greater than 0 and less than 10.

n % 2 == 0 or n % 3 == 0 is true if either of the conditions is true, that is, if the number is divisible by 2 or 3.

Finally, the not operator negates a boolean expression, so not(x > y) is true if (x > y) is false, that is, if x is less than or equal to y.

4.4. Conditional execution

In order to write useful programs, we almost always need the ability to check conditions and change the behavior of the program accordingly. Conditional statements give us this ability. The simplest form is the ** if statement**:

if x > 0:

   print "x is positive"

The boolean expression after the if statement is called the condition. If it is true, then the indented statement gets executed. If not, nothing happens.

The syntax for an if statement looks like this:

if BOOLEAN EXPRESSION:

   STATEMENTS

As with the function definition from last chapter and other compound statements, the if statement consists of a header and a body. The header begins with the keyword if followed by a boolean expression and ends with a colon (:).

The indented statements that follow are called a block. The first unindented statement marks the end of the block. A statement block inside a compound statement is called the body of the statement.

Each of the statements inside the body are executed in order if the boolean expression evaluates to True. The entire block is skipped if the boolean expression evaluates to False.

There is no limit on the number of statements that can appear in the body of an if statement, but there has to be at least one. Occasionally, it is useful to have a body with no statements (usually as a place keeper for code you haven’t written yet). In that case, you can use the pass statement, which does nothing.

if True:          # This is always true

   pass          # so this is always executed, but it does nothing


Related Questions

Which idea generation method involves keeping ideas in sight and well-organized?
Mind Mapping
Synectics
Brainstorming
Design Boards

Answers

I believe that it would be mind mapping

Answer:

um i pink A, and C cause you can look in your mind to find idea if mind mapping means by that and you can brainstorm for other idea later for other thing that you need idea for that my answer if it not help you then i am sorry if did plz mark me brainliest if you can

Explanation:

Other Questions
I need help can someone tell me which choice is correct? hii! please help asap. ill give brainliest what happened in mexico when the oil spill from 2010how did it start and how did it end What is the correct meaning of catapult?Mounting tension between England and the colonies helped catapult Washingtons rank in the Continental Army.A) hamperB) defineC) improveD) propelIm stuck between C and D Nancy and Joan bought a small farm for $300,000 under an installment land contract with a $50,000 down payment. They will pay interest only at 6% for five years when the remaining principal balance becomes due. How much interest will they pay over the life of the contract? What most likely causes water to change from the liquid state to a gas in the water cycle?A. energy from gravityB. energy from the SunC. energy from moving waterD. energy from the Earth's core What is the name of this region? Based on the number of voids, a ferrite slab is classified as either high, medium, or low. Historically, 5% of the slabs are classified as high, 85% as medium, and 10% as low. A group of 20 slabs that are independent regarding voids is selected for test ing. Let X, Y, and Z denote the number of slabs that are classified as high, medium, and low, respectively. (a) What are the name and values of the parameters of the joint probability distribution of X, Y , andZ?(b) What is the range of the joint probability distribution of X, Y, and Z?(c) What are the name and the values of the parameters of the marginal probability distribution of X?(d) Determine E[X] and Var(X).Determine the following:(e) P{X = 1, Y = 17, Z = 3}(f) P{X ? 1, Y = 17, Z = 3}(g) P{X ? 1}(h) E[Y ] Explain find the vertex and the x- and y- intercept of the following quadratic equations y = 5x +15x+10 Hey guys I got a question how do you get exercise Briefly explain the point of view about immigration and Native Americans expressed bythe artist. the first term of an arithmetic sequence is 10 and the sum of the first five terms is 250,find the sequence A pie has a diameter of 9 inches. What is the circumference of the pie What was life like in Germany after the Versailles Treaty? Eyewitness Accounts of the Holocaust . How should the Holocaust be remembered today and in the future? 1. What section of the country grew cotton and tobacco?2. Fill in the Blank: _____________ was a champion of states' rights. Henry Clay OR John C. Calhounpls help thxxxx What is the volume of the prism, In cubic inches? please i need your help i cant fail this class PLEASE HELP!!Which of the following best explains why Marbury v. Madison is considered the Supreme Court's landmark decision on judicial review?1.It was the first case in which the Supreme Court ruled that an act of Congress was legal.2.t was the first case under which the Supreme Court reviewed and struck down presidential legislation.3.It was the first case in which the Supreme Court struck down an act of Congress as unconstitutional.4.It was the first case in a series of cases concerning the constitutionality of wage legislation.