141k views
4 votes
Given x and y, each associated with an int, write a fragment of code that associates the larger of these with another variable named max.

User BJoe
by
4.5k points

1 Answer

6 votes

Answer:

The program to this question as follows:

Program:

x=int(input('Input the first number: ')) #defining variable x and input value by user

y=int(input('Input the second number: ')) #defining variable y and input value by user

if x > y: #if block to check value x>y

max=x #define variable max that hold variable x value

print('max number is: ', x) #print value

else: #else block

max=y #define variable max that holds variable y value

print('max number is: ', y) #print value

Output:

Input the first number: 22

Input the second number: 33

max number is: 33

Explanation:

In the above code two-variable, "x and y" is defined, which holds a value, which is input by the variable. In the next step, the if block statement is used that can be described as follows:

  • In the if block, it will check x is greater than y it will define a variable, that is "max", that holds variable x value and prints its value.
  • In the else block, if the above condition is false it uses the max variable, that holds variable y value and prints its value.
User Mohammad Zare
by
5.5k points