How do i make an even odd game in python?

Given three positive integers X, Y and P. Here P denotes the number of turns. Whenever the turn is odd X is multiplied by 2 and in every even turn Y is multiplied by 2. The task is to find the value of max(X, Y) ÷ min(X, Y) after the complete P turns.

Examples : 

Input : X = 1, Y = 2, P = 1
Output : 1
Explanation: As turn is odd, X is multiplied by
2 and becomes 2. Now, X is 2 and Y is also 2. 
Therefore, 2 ÷ 2 is 1.

Input : X = 3, Y = 7, p = 2
Output : 2
Explanation: Here we have 2 turns. In the 1st turn which is odd
X is multiplied by 2. And the values are 6 and 7. 
In the next turn which is even Y is multiplied by 2.
Now the final values are 6 and 14. Therefore, 14 ÷ 6 is 2.

Lets play the above game for 8 turns : 
 

| i    | 0 | 1  | 2  | 3  | 4  | 5  | 6  | 7   | 8   |
|------|---|----|----|----|----|----|----|-----|-----|
| X(i) | X | 2X | 2X | 4X | 4X | 8X | 8X | 16X | 16X |
| Y(i) | Y | Y  | 2Y | 2Y | 4Y | 4Y | 8Y | 8Y  | 16Y |

Here we can easily spot a pattern : 
 

if i is even, then X(i) = z * X and Y(i) = z * Y.
if i is odd, then X(i) = 2*z * X and Y(i) = z * Y.

Here z is actually the power of 2. So, we can simply say – 
 

If P is even output will be max(X, Y) ÷ min(X, Y) 
else output will be max(2*X, Y) ÷ min(2*X, Y).

Below is the implementation : 

C++

#include

using namespace std;

int findValue(int X, int Y, int P)

{

    if (P % 2 == 0)

        return (max(X, Y) / min(X, Y));

    else

        return (max(2 * X, Y) / min(2 * X, Y));

}

int main()

{

    int X = 1, Y = 2, P = 1;

    cout << findValue(X, Y, P) << endl;

    X = 3, Y = 7, P = 2;

    cout << findValue(X, Y, P) << endl;

}

C

#include

int findValue(int X, int Y, int P)

{

    int Max = X,Min = X;

    if(Max < Y)

      Max = Y;

    if(Min > Y)

      Min = Y;

    int Max2 = 2*X,Min2 = 2*X;

    if(Max2 < Y)

      Max2 = Y;

    if(Min2 > Y)

      Min2 = Y ;

    if (P % 2 == 0)

        return (Max / Min);

    else

        return (Max2 / Min2);

}

int main()

{

    int X = 1, Y = 2, P = 1;

    printf("%d\n",findValue(X, Y, P));

    X = 3, Y = 7, P = 2;

    printf("%d\n",findValue(X, Y, P));

}

Java

import java.util.*;

class Even_odd{

    public static int findValue(int X, int Y,

                                        int P)

    {

        if (P % 2 == 0)

            return (Math.max(X, Y) /

                            Math.min(X, Y));

        else

            return (Math.max(2 * X, Y) /

                            Math.min(2 * X, Y));

    }

    public static void main(String[] args)

    {

        int X = 1, Y = 2, P = 1;

        System.out.println(findValue(X, Y, P));

        X = 3;

        Y = 7;

        P = 2;

        System.out.print(findValue(X, Y, P));

    }

}

Python3

def findValue( X , Y , P ):

    if P % 2 == 0:

        return int(max(X, Y) / min(X, Y))

    else:

        return int(max(2 * X, Y) / min(2 * X, Y))

X = 1

Y = 2

P = 1

print(findValue(X, Y, P))

X = 3

Y = 7

P = 2

print((findValue(X, Y, P)))

C#

using System;

class GFG

{

    public static int findValue(int X, int Y,

                                        int P)

    {

        if (P % 2 == 0)

            return (Math.Max(X, Y) /

                    Math.Min(X, Y));

        else

            return (Math.Max(2 * X, Y) /

                    Math.Min(2 * X, Y));

    }

    public static void Main()

    {

        int X = 1, Y = 2, P = 1;

        Console.WriteLine(findValue(X, Y, P));

        X = 3;

        Y = 7;

        P = 2;

        Console.WriteLine(findValue(X, Y, P));

    }

}

PHP

function findValue($X, $Y, $P)

{

    if ($P % 2 == 0)

        return (int)(max($X, $Y) /

                     min($X, $Y));

    else

        return (int)(max(2 * $X, $Y) /

                     min(2 * $X, $Y));

}

$X = 1;

$Y = 2;

$P = 1;

echo findValue($X, $Y, $P), "\n";

$X = 3; $Y = 7; $P = 2;

echo findValue($X, $Y, $P), "\n";

?>

Javascript

Time Complexity: O(1)
Auxiliary Space: O(1)


How do you make a even odd program in Python?

num = int (input (“Enter any number to test whether it is odd or even: “) if (num % 2) == 0: print (“The number is even”) else: print (“The provided number is odd”) Output: Enter any number to test whether it is odd or even: 887 887 is odd. The program above only accepts integers as input.

How do you print even and odd list in Python?

Python Program to Print Even and Odd Numbers in a List.
num_list=[].
n=int(input("Enter the Starting of the range:")).
k=int(input("Enter the Ending of the range:")).
for i in range(n,k):.
num_list. append(i).
print("Original Number List:", num_list).
even_list=[].
odd_list=[].

How do you program odd and even numbers?

Program to Check Even or Odd If the number is perfectly divisible by 2 , test expression number%2 == 0 evaluates to 1 (true). This means the number is even. However, if the test expression evaluates to 0 (false), the number is odd.

How do you print even and odd numbers in Python while loop?

Python Code: num = int(input("Enter a number: ")) mod = num % 2 if mod > 0: print("This is an odd number. ") else: print("This is an even number. ")