Question

In: Computer Science

Python # Write a program that examines three variables—x, y, and z # and prints the...

Python
# Write a program that examines three variables—x, y, and z
# and prints the largest odd number among them.
# If none of them are odd, it should print a message to that effect.

n = input('Enter the 1st Integer x: ')
x = int(n)
n = input('Enter the 2nd Integer y: ')
y = int(n)
n = input('Enter the 3rd Integer z: ')
z = int(n)

if x % 2 == 0 and y % 2 == 0 and z % 2 == 0:
print ("None of them are odd")

if x % 2 == 1 and (x >= y or y % 2 == 0) and (x >= z or z % 2 == 0):
print (x,'- x is largest')

if y % 2 == 1 and (y >= x or x % 2 == 0) and (y >= z or z % 2 == 0):
print (y,'- y is largest')

if z % 2 == 1 and (z >= x or x % 2 == 0) and (z >= y or y % 2 == 0):
print (z,'- z is largest')
  

(a) Come up with the natural partition and test case for the above program.

Solutions

Expert Solution

n = input('Enter the 1st Integer x: ')
x = int(n)
n = input('Enter the 2nd Integer y: ')
y = int(n)
n = input('Enter the 3rd Integer z: ')
z = int(n)

if x % 2 == 0 and y % 2 == 0 and z % 2 == 0:
print ("None of them are odd")

if x % 2 == 1 and (x >= y or y % 2 == 0) and (x >= z or z % 2 == 0):
print (x,'- x is largest')

if y % 2 == 1 and (y >= x or x % 2 == 0) and (y >= z or z % 2 == 0):
print (y,'- y is largest')

if z % 2 == 1 and (z >= x or x % 2 == 0) and (z >= y or y % 2 == 0):
print (z,'- z is largest')

beaware of indentation

try to type the code


Related Solutions

In the python code below, describe the scope of the variables x, y, z and u....
In the python code below, describe the scope of the variables x, y, z and u. def my_func(x):         y = x - 2         return y z = 6 if z > 4:           u = my_func(6)          print(u)
1) Generate a data set with three variables (X, Y and Z). X and Y have...
1) Generate a data set with three variables (X, Y and Z). X and Y have 10 observations for each (N=10), and Z has 13 observations (N=13). Each observation should have two digits (such as “83” or “8.3”). 2) Draw a stem-and-leaf display for variable Z only and draw a box plot display for variable Z after specifying the 5 numbers (UEX, LEX, FU, FL, MD). 3) Calculate the mean and standard deviation for variable X 4) Calculate the mean...
If X, Y and Z are three arbitrary vectors, prove these identities: a. (X×Y).Z = X.(Y×Z)...
If X, Y and Z are three arbitrary vectors, prove these identities: a. (X×Y).Z = X.(Y×Z) b. X×(Y×Z) = (X.Z)Y – (X.Y)Z c. X.(Y×Z) = -Y.(X×Z)
The joint density function for random variables X, Y, and Z is f(x, y, z)= Cxyz  if...
The joint density function for random variables X, Y, and Z is f(x, y, z)= Cxyz  if 0 ≤ x ≤ 1, 0 ≤ y ≤ 2, 0 ≤ z ≤ 2, and f(x, y, z) = 0 otherwise. (a) Find the value of the constant C. (b) Find P(X ≤ 1, Y ≤ 1, Z ≤ 1). (c) Find P(X + Y + Z ≤ 1).
In Python Which statement has a syntax error? Assume variables x, y, z, and age have...
In Python Which statement has a syntax error? Assume variables x, y, z, and age have already been defined. a. y = y b. x + y = z c. age = '32' d. print('Name, age') e. None of the above Which statement does not print a newline character at the end? a. print('First part…') b. print('First part…\n') c. print('First part…', end='') d. print('First part…', end=”-\n”) e. None of the above Which function converts a string to an integer? a....
Write a C program which prints the environment variables to a file "sample.txt" . All variables...
Write a C program which prints the environment variables to a file "sample.txt" . All variables are followed by a newline character. example: example: inputs: envp/environ = {"E1=5","E2=9",NULL} outputs: env.txt as a string would be "E1=5\nE2=9\n".
Write a program for Sense HAT (or the emulator) to map X, Y, and Z acceleration...
Write a program for Sense HAT (or the emulator) to map X, Y, and Z acceleration (or orientation) values into R, G, and B color values on the LED matrix. That way, when you tilt the Sense HAT, the LED matrix will display different colors to simulate a paint mixer. When you write your program, please consider using delay to avoid the problem of changing color too fast to be perceived. Also, you want to make sure that you map...
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
[x, y, and z are integer variables, which expressions are equivalent to each other?] a. (x==y...
[x, y, and z are integer variables, which expressions are equivalent to each other?] a. (x==y && x !=z) || (x!=y && x==z) b. (x==y || x==z) && (x!=y || x!=z) c. (x==y) != (x==z)
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT