answer in python
obtain a number from the user and display its double if even otherwise display its half
Answers
Answered by
7
#obtaining the input
n = int(input("Enter a number: "))
#using conditional statements to test if it's odd/even
if n%2 == 0:
print(n*2, "is", str(n) + "'s double.")
else:
print(n/2, "is", str(n) + "'s half.")
- input() is a function that enables a user to give data to the compiler.
- int() is a datatype that can be used with input() in order to take in an integer type value from the user. Keep in mind that entering decimal values when using int() will result in an error.
Conditional statements are statements used to test for conditions in order to decide the next step/command to be followed.
In this case, we were testing if n was an odd/even number, as per the questions asks for. If it was odd, we needed to print its half, otherwise its double.
Similar questions