0% found this document useful (0 votes)
67 views11 pages

Assignment Objectives: Dr. Anil Saroliya

The document contains instructions for several PHP coding assignments: 1. The first assignment asks to write code that manipulates a single variable through arithmetic-assignment operators to produce the given output values. 2. The second assignment involves using single and double quotes to concatenate a string using a variable. 3. The third assignment uses an if/else conditional to print different responses depending on the current month. 4. The fourth assignment uses a for loop to print the squares of numbers 1-12. 5. The fifth assignment uses nested for loops to generate a multiplication table.

Uploaded by

Yusuf Zokirjon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views11 pages

Assignment Objectives: Dr. Anil Saroliya

The document contains instructions for several PHP coding assignments: 1. The first assignment asks to write code that manipulates a single variable through arithmetic-assignment operators to produce the given output values. 2. The second assignment involves using single and double quotes to concatenate a string using a variable. 3. The third assignment uses an if/else conditional to print different responses depending on the current month. 4. The fourth assignment uses a for loop to print the squares of numbers 1-12. 5. The fifth assignment uses nested for loops to generate a multiplication table.

Uploaded by

Yusuf Zokirjon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Dr.

Anil Saroliya:____________

Lab-1
Assignment: Create your personal profile site using HTML, CSS, etc.
Objectives: Learn basics of HTML&CSS and make simple website.

Solution:
HTML code:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<h1> <center>Это мой профиль</center> </h1>
<nav>
<a href="#">Home</a>
<a href="#">About me</a>
<a href="#">Qualification</a>
<a href="#">Contacts</a>
</nav>
<div class="con">
<h2><center>Experience</center></h2>
<div class="sub_con">
<p> Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Dolorem vero id officiis consequuntur
eos deserunt officia magni accusamus voluptatibus est at
accusantium fugiat assumenda dolor quod tempora quas, fugit
facilis dolores incidunt vitae nulla voluptate quidem laudantium.
Quam rem unde cum ipsam, nihil saepe repellat porro velit id
molestias maiores deleniti perspiciatis impedit illum minima ex.
Pariatur alias dicta ratione sapiente quos ipsa ex consequuntur
sit vel. Quidem voluptates aperiam reiciendis sunt. Officiis,
fuga, ipsa enim esse inventore nam nisi voluptate impedit
laudantium blanditiis minus nesciunt ab odit architecto
voluptatibus obcaecati amet velit illo magnam expedita
ratione. Aperiam, hic dolores. </p>
<img src="eqwe.jpg" alt="wal">
</div>
<div class="pics">
<img class="img" src="wal.jpg" alt="wal">
<img class="img"src="wal.jpg" alt="wal">
<img class="img"src="wal.jpg" alt="wal">
</div>
</div>
</body>
</html>

CSS code:
body{
width: 50%;
}
nav{
align-items: center;
background-color: grey;
padding: 10px;
display: flex;
justify-content: space-around;
}
a{
text-decoration: none;
}
img{
width: 250px;
}
.img{
width: 250px;
}
.sub_con{
display: flex;
justify-content: space-between;
}
.pics{
margin-top: 20px;
display: flex;
justify-content: space-between;
}
p{
width: 400px;
}
Dr. Anil Saroliya:____________

Lab-2
Assignment: Do the exercises mentioned below.
Objectives: Get closer to syntax of the language and write simple codes.

1. Arithmetic-assignment operators perform an arithmetic operation on the variable at the same


time as assigning a new value. For this PHP exercise, write a script to reproduce the output below.
Manipulate only one variable using no simple arithmetic operators to produce the values given in the
statements.
• Hint: In the script each statement ends with "Value is now $variable."
Value is now 8.
Add 2. Value is now 10.
Subtract 4. Value is now 6.
Multiply by 5. Value is now 30.
Divide by 3. Value is now 10.
Increment value by one. Value is now 11.
Decrement value by one. Value is now 10.

Code: Output:
<?php

$val = 8;
echo "Value is now $val <br>";
$val += 2;
echo "Value is now $val <br>";
$val -= 4;
echo "Value is now $val <br>";
$val *= 10;
echo "Value is now $val <br>";
$val /=3;
echo "Value is now $val <br>";
$val++;
echo "Value is now $val <br>";
$val--;
echo "Value is now $val <br>";

?>

2. For this PHP exercise, write a script using the following variable:
$around="around";
•Single quotes and double quotes don't work the same way in PHP. Using single quotes (' ') and the
concatenation operator, echo the following to the browser, using the variable you created:
What goes around, comes around.
Code:
$around="around";
echo 'What goes '.$around. ', comes ' .$around;

Output:
What goes around, comes around
3. In this PHP exercise, you will use a conditional statement to determine what gets printed to the
browser. Write a script that gets the current month and prints one of the following responses, depending
on whether it's August or not:
It’s September, so it’s somehow hot.
Not September, so at least not in the peak of the heat.
•Hint: the function to get the current month is 'date('F', time())' for the
month's full name.
Code:
$month = date("m");
if ($month == 9) {
echo "<br>It’s September, so it’s somehow hot <br>";
}
else {
echo "Not September, so at least not in the peak of the heat.";
}

Output:
Not September, so at least not in the peak of the heat.

4. Loops are very useful in creating lists and tables. In this PHP exercise, you will use a loop to create a
list of equations for squares.•Using a for loop, write a script that will send to the browser a list of
squares for the numbers 1-12.
Use the format, "1 * 1 = 1", and be sure to include code to print each
formula on a different line

Code:
<?php
$x = 1;
$y = 12;
for($x; $x <= $y; $x++) {
  for($z=1; $z <= $y; $z++){
    echo "<br>$x * $z = " . $x * $z . "<br>";
 }
}

Output:

5. HTML tables involve a lot of repetitive coding - a perfect place to use for loops.
You can do even more if you nest the for loops.
• In this PHP exercise, use two for loops, one nested inside another. Create the
following multiplication table:

Code:
<style>
  table {
    border-collapse: collapse;
    width: 100%;
 }
  td {
    background-color: yellow;
    border: 1px solid black;
 }
</style>

<?php
$rows = [];

$x= 1;
$y= 7;

for($x; $x<= $y; $x++) {


  $row_column = [];
  for($z= 1; $z<= $y; $z++){
    array_push($row_column, $x* $z);
 }
  array_push($rows, $row_column);
}
?>

<table>
  <?php foreach ($rows as $row): ?>
    <tr>
      <?php foreach ($row as $column): ?>
        <td><?= $column ?></td>
      <?php endforeach; ?>      
    </tr>
  <?php endforeach; ?>
</table>

Output:

Lab-5
Lab Assignment-5
Write a PHP program using nested for loop that creates a chess board.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   <table width="270px" cellspacing="0px" cellpadding="0px" border="1px">
   <!-- cell 270px wide (8 columns x 60px) -->
    <?php
      for($row=1;$row<=8;$row++)
   {
          echo "<tr>";
          for($col=1;$col<=8;$col++)
     {
          $total=$row+$col;
          if($total%2==0)
     {
          echo "<td height=30px width=30px bgcolor=#FFFFFF></td>";
     }
          else
     {
          echo "<td height=30px width=30px bgcolor=#000000></td>";
     }
     }
          echo "</tr>";
    }
    ?>
  </table>
  </body>
</html>

Output:

Write a PHP program to calculate electricity bill using if-else conditions.


Conditions:
For first 50 units – $ .350/unit
For next 100 units – $ .400/unit
For next 100 units – $ .520/unit
For units above 250 – $ .650/unit

Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<?php
$result_str = $result = '';
if (isset($_POST['unit-submit'])) {
    $units = $_POST['units'];
    if (!empty($units)) {
        $result = calculate($units);
        $result_str = 'Total amount of ' . $units . ' - ' . $result;
  }
}

function calculate($units) {
    $first = 3.50;
    $second = 4.00;
    $third = 5.20;
    $fourth = 6.50;

    if($units <= 50) {


        $bill = $units * $first;
  }
    else if($units > 50 && $units <= 100) {
        $temp = 50 * $first;
        $remaining = $units - 50;
        $bill = $temp + ($remaining * $second);
  }
    else if($units > 100 && $units <= 200) {
        $temp = (50 * 3.5) + (100 * $second);
        $remaining = $units - 150;
        $bill = $temp + ($remaining * $third);
  }
    else {
        $temp = (50 * 3.5) + (100 * $second) + (100 * $third);
        $remaining = $units - 250;
        $bill = $temp + ($remaining * $fourth);
  }
    return number_format((float)$bill, 2, '.', '');
}

?>

<body>
        <h1>Php - Calculate Electricity Bill</h1>

        <form action="" method="post">


                <input type="number" name="units" placeholder="Please enter no. of Units" />
                <input type="submit" name="unit-submit" value="Submit" />
        </form>
            <?php echo '<br />' . $result_str; ?>
</body>
</html>

Output:

You might also like