Answer:
1 <?php
2 if (isset($_GET["submit"])) {
3 echo "Welcome " . $_GET["name"];
4 }
5 ?>
6
7
8 <form method="get">
9 <input name="name" type="text" placeholder="Enter your name"/>
10 <button name="submit" type="submit">Submit</button>
11 </form>
12
13 <?php
14 ?>
<h2>
Explanation:</h2>
Lines 1 - 5 check if the user has clicked on the submit button.
If the button has been clicked the a welcome message is
shown.
Lines 8 - 11 create a form to hold the text box and the submit button
Give the form a <em>method</em> attribute of value <em>get [Line 8]</em>
<em> </em>Give the input field a <em>name</em> attribute of value <em>name </em>and a
placeholder attribute of value <em>Enter your name [Line 9]</em>
<em> </em>Give the button a <em>name </em>attribute of value <em>submit</em> and a <em>type</em>
attribute of value <em>submit</em> <em>[Line 10]</em>
<em />
<em />
<em />
<em />
PS: Save the file as a .php file and run it on your server. Be sure to remove the line numbers before saving. A sample web page is attached to this response.
Answer:
Explanation:
def the_perfect(n):
try: #exception handling if n is a negative number
n > 0
except: #return -1 if the error is reached
return -1
else:
total = 0
for i in range(1, n): #for loop from 1 to the target number
if n % i == 0:
total += i
return total == n #should return true if number is perfect number
print(perfect_number(8))
Did they give you any Answer options
Answer:
for (i = lo, result = 0; i <= hi; result += i, i++) {}
Explanation:
A for loop header has three statements:
- <em>i = 0, result = 0; </em>This statement initializes <u>i</u> and <u>result</u> variables with 0. It is executed only once at the very start of the for loop.
- <em>i <= hi;</em> This statement is executed after the first statement and again after the execution of code in body of the loop.
- <em>result += i, i++</em> This statement is executed after the execution of code in body of the loop but before the execution of second statement.
Therefore, the following sequence of events will occur:
- The result variable is initialized with 0 at start.
- Then, the condition is checked. If the value of i will be less than or equal to the value of hi, the third statement will be executed.
- The third statement will add the value of i to the value of result and then increase the value of i by 1.
- Then, again the condition in second statement will be checked.
This loop will be executed for as long as the condition remains true.