Question

Write a script that uses a conditional operator to determine whether a variable contains a number...

Write a script that uses a conditional operator to determine whether a variable contains a number and whether the number is even. You need to use the is_numeric () function and the conditional operator. For floating-point number, you need to use the round () function to convert the value to the nearest whole number. Save the document as IsEven.php.

Homework Answers

Answer #1

php code is as follows,

save the file name as IsEven.php :

<?php
//declare an assign a variable called num
$num = 11.60;
/*using is_numeric() function inside if conditional operator
to determine whether the variable num is number or not
*/
if (is_numeric($num)) {
/* using round() function to convert
the value to the nearest whole number*/
/* if conditional operator is used
to determine whether the variable num is even or not*/
   if(round($num) % 2 == 0){
echo "Even number";
}
else{
echo "Odd number";
}
   }
//enters else block if is_numeric returns false
   else {
       echo " is not numeric";
   }

?>

output screenshots for different values of num variable:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1- Create a new script that is called HW9.m and save it. The script will do...
1- Create a new script that is called HW9.m and save it. The script will do the following. Test your code for each of the cases and upload your script as a .m file. [15 points] a. Create a random integer numbers that goes from 0 to 5 and assign it to a variable y using rand and round commands. Hint: Note that rand function only creates random number between 0 and 1. You need to scale the values to...
write a script named print_lines.sh that uses head and tail together to print out a specific...
write a script named print_lines.sh that uses head and tail together to print out a specific set of lines from a file. The script should take three arguments: the line number to start at, the line number to stop at, and the file to use. Here's an example run: [user@localhost ~]$ print_lines.sh 7 10 /etc/passwd shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin [user@localhost ~]$ In this example, the script prints line 7 through 10 (inclusive) of the /etc/passwd file. Your script must do...
Write a C program to check whether given number is prime or not by performing following...
Write a C program to check whether given number is prime or not by performing following steps: Define an integer variable as given_number.   Use the C function scanf to read the integer variable given_number. Use the conditional statement to find out given_number is prime or not prime. Print the final output as The number is prime or The number is not prime. Compile and test the program on CS Linux systems
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set it equal to the empty string (NAME=””). Create a variable called NAME_LENGTH and set it equal to the length of your last name. Output the value of the NAME variable to show that it is empty. 2. Write a FOR loop that executes as many times as there are letters in your name (use the NAME_LENGTH variable in your condition). Use a CASE statement...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
Using Python, write the following code. You are to allow the user to enter the daily...
Using Python, write the following code. You are to allow the user to enter the daily temperature as a floating-point number. You should make the assumption that you are recording temperatures in Fahrenheit. You should allow the user to continue entering temperatures until the value -999 is entered. This number should not be considered a temperature, but just a flag to stop the program. As the user enters a temperature, you should display the following each time: Current Temperature: 999...
Ocean City Kite Company manufactures & sells kites for $8.50 each. The variable cost per kite...
Ocean City Kite Company manufactures & sells kites for $8.50 each. The variable cost per kite is $3.00 with the current annual sales volume of 70,000 kites. This volume is currently Ocean City Kite's breaking even point. Use this information to determine the dollar amount of Ocean City Kite Company's fixed costs. (Round dollar value to the nearest whole dollar & enter as whole dollars only.)
Write a function to check if a machine uses little endian or big endian notation. write...
Write a function to check if a machine uses little endian or big endian notation. write the function checkEndianess(), complete the main function implementation to print the value returned by the function and print if the machine is “Little Endian” or “Big Endian”, compile and run the program. The function checkEndianess() should return the following values: • 0 if the architecture is "Little Endian" • 1 if the architecture is "Big Endian". #include int main() { int check; // Variable:...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits by following the instructions noted below. The input signal and impulse response generation should be done in the function. The test bench script should be used only to call the function and for signal plotting purposes. No plotting should be done inside the function itself. Name your function L2_C Instructions: Input voltage ,x(t), can be AC or DC. Consider a variable ‘w1’ which can...