Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Python, From the keyboard take in a number. Determine if the number is odd or

ID: 3851963 • Letter: I

Question

In Python, From the keyboard take in a number. Determine if the number is odd or even. If the number is even square the value. If the number is odd cube the value. This should be computed using the conditional expression. The conditional operator is NOT an if else. It is a substitute for it. Once you have computed the value output it to the screen. Do not use print in conjunction with the conditional expression. Do NOT duplicate variable assignment within the conditional expression. Assign the value to the variable once.

Explanation / Answer

n = int(input("Enter a number: ")) #taking the number from the user
rem = n % 2 #calculatng the remainder
if rem > 0: #checking for odd or even   
c=n*n*n #calculatng the cube
print("The answer is ",c)
else:
c=n*n #calculatng the square
print("The answer is ",c)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote