Question

In: Computer Science

using python: Given an arbitrary whole number, please write an if statement to output if it...

using python:

Given an arbitrary whole number, please write an if statement to output if it is an even number or an odd number

Solutions

Expert Solution

We know that a number is even if it is exactly divisible by 2, i.e., remainder is 0 . So we make use % operator available in python to check whether the remaninder is 0 when divided by 2. If the remainder is 0 we print that the number is an even number, else we print that the number is an odd number.

COde for the above operation is given below.


num=int(input("Enter the number"));  #taking input from the user

if (num%2==0):    #checking for the remaninder
    print(num,'is an even number');  # if 0 print that it is even number
else:
    print(num,'is an odd number'); # else print it is odd number

output for variour inputs are shown below.

Hope you got the answer. If you still have any doubts regarding this, please try to comment. I will help you with that.


Related Solutions

Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]. Remember, base 16 needs to be calculated as hexadecimal. So, if radix-d is input as a hexadecimal number, it needs to convert and output to desired base. Conversely, if base 16 is the desired output, then the output needs to show a hexadecimal number. Hints: The easiest approach is...
(Python) Implement a function to compute a sum that can compute sum for an arbitrary number...
(Python) Implement a function to compute a sum that can compute sum for an arbitrary number of input integers or float numbers. In other words, calls like this should all work: flexible_sum(x1, x2) # sum of two integer or float numbers or strings x1 and x2 flexible_sum(x1, x2, x3) # sum of 3 input parameters and can also handle a single input parameter, returning it unchanged and with the same type, i.e.:   flexible_sum(1) returns 1 and can accept an arbitrary...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to...
Please attach the output screenshots, narrative descriptions, or paste the Python codes. Please write code to print the type of the following variables. Please write down the codes and the output as well. x = 3.5 y = '3.5' z = {1:'John', 2:'Wick', 3:'Barry', 4:'Allen'}
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
please write simple python 3 program with explanations and correct output Bilbo and problems on the...
please write simple python 3 program with explanations and correct output Bilbo and problems on the board Problem Statement Bilbo once reached his maths claws earlier than anyone else.He saw some N unique numbers greater than 0 written on the board.He thought of challenging his classmates when they come.So for each number i,he wrote the number before and after it on a paper slip.If it is the last number then the number after it is assumed to be 0.If it...
Given n. Write a program in PYTHON to Generate all numbers with number of digits equal...
Given n. Write a program in PYTHON to Generate all numbers with number of digits equal to n, such that the digit to the right is greater than the left digit (ai+1 > ai). E.g. if n=3 (123,124,125,……129,234,…..789)
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two...
Please attach the output screenshots, narrative descriptions, or paste the Python codes when requested. Given two exam scores, exam_1 and exam_2, write a program to determine if the student makes progress (exam_2 is greater than exam_1). Return “Yes” or “No”. You can use any exam_1 score and exam_2 score for this exercise.
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs...
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs and prints the number of even and odd inputs in the sequence. please explain. Thanks
Important: please use python. Using while loop, write python code to print the times table (from...
Important: please use python. Using while loop, write python code to print the times table (from 0 to 20, incremented by 2) for number 5. Add asterisks (****) so the output looks exactly as shown below.   Please send the code and the output of the program. ****************************************************************** This Program Shows Times Table for Number 5 (from 0 to 20) Incremented by 2 * ****************************************************************** 0 x 5 = 0 2 x 5 = 10 4 x 5 = 20 6...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT