223k views
2 votes
Add a selection statement that will determine which number is larger, or if there is a tie. The best way to do this is to create a nested if else where you first check to see if p1number is equal to p2number

2 Answers

2 votes

Answer:

# user is prompt to enter p1

p1 = int(input("Enter P1: "))

# user is prompt to enter p2

p2 = int(input("Enter P2: "))

# check if p1 is not equals to p2

if(p1 != p2):

# check if p1 is greater than p2

# then it displays p1 is greater

if(p1 > p2):

print("p1 is greater than p2")

# check if p2 is greater than p1

# then it displays p2 is greater

elif(p2 > p1):

print("p2 is greater than p1")

# else it displays that p1 and p2 are equal

else:

print("There is a tie for p1 and p2")

Step-by-step explanation:

The code snippet is written in Python and is well commented.

User Original
by
4.0k points
6 votes

Answer:

  1. p1number = 4
  2. p2number = 7
  3. if(p1number != p2number):
  4. if(p1number > p2number):
  5. print("p1number is bigger than p2number")
  6. else:
  7. print("p2number is bigger than p1number")
  8. else:
  9. print("There is a tie")

Step-by-step explanation:

The solution is written in Python 3.

Firstly, create two variables p1number and p2number (Line 1-2). Assign a random number to the variables, respectively (e.g. 4 and 7).

Create a if statement to check if p1number not equal to p2number (Line 4). If so, proceed to check if p1number bigger than p2number (Line 5). If true, print the message "p1number is bigger than p2number" or vice versa.

If p1number equal to p2number, print the message "There is a tie" (Line 10).

User Ufos
by
4.6k points