PHP exercises (1), PHP exercises (_PHP tutorial
PHP practice questions (1), PHP practice questions (
Program 1.
Title: The bonus issued by the company is based on the profit. When the profit (I) is less than or equal to 100,000 yuan, the bonus can be increased by 10%; when the profit is more than 100,000 yuan, and less than 200,000 yuan, the portion less than 100,000 yuan will be paid. The commission is 10%, and the commission is 7.5% for the portion above 100,000 yuan; the commission is 5% for the portion above 200,000 yuan between 200,000 and 400,000; the commission is 5% for the portion above 400,000 yuan. 1%, enter the current month’s profit I from the keyboard, what is the total number of bonuses to be distributed? (Use if else if)
<span> 1</span> <span>$I</span> = 4324128<span>; </span><span> 2</span> <span>$bonus</span> = 0; <span>//</span><span> 奖金数</span> <span> 3</span> <span> 4</span> <span>if</span> (<span>$I</span> <= 100000<span>) { </span><span> 5</span> <span>$bonus</span> = <span>$I</span> * 1/10<span>; </span><span> 6</span> } <span>else</span> <span>if</span> (<span>$I</span> > 100000 && <span>$I</span> < 200000<span>) { </span><span> 7</span> <span>$bonus</span> = <span>$I</span> % 100000 * 7.5/100 + (<span>$I</span> - <span>$I</span> % 100000) * 1/10<span>; </span><span> 8</span> } <span>else</span> <span>if</span> (<span>$I</span> >= 200000 && <span>$I</span> < 400000<span>) { </span><span> 9</span> <span>$bonus</span> = (<span>$I</span> - 200000) * 5/100 + (<span>$I</span> % 100000 * 7.5/100) + (<span>$I</span> - <span>$I</span> % 100000) * 1/10<span>; </span><span>10</span> } <span>else</span><span> { </span><span>11</span> <span>$bonus</span> = (<span>$I</span> - 400000) * 1/100 + (<span>$I</span> - 200000) * 5/100 + (<span>$I</span> % 100000 * 7.5/100) + (<span>$I</span> - <span>$I</span> % 100000) * 1/10<span>; </span><span>12</span> <span>} </span><span>13</span> <span>14</span> <span>echo</span> 'bonus :' . <span>$bonus</span>.'<br/>';
Program 2.
Title: Enter three integers x, y, z and find the largest number;
<span>1</span> <span>$x</span> = 4<span>; </span><span>2</span> <span>$y</span> = 7<span>; </span><span>3</span> <span>$z</span> = 2<span>; </span><span>4</span> <span>5</span> <span>$max</span> = <span>$x</span>><span>$y</span> ? <span>$x</span> : <span>$y</span><span>; </span><span>6</span> <span>$max</span> = <span>$z</span>><span>$max</span> ? <span>$z</span> : <span>$max</span><span>; </span><span>7</span> <span>8</span> <span>echo</span> 'max number :' . <span>$max</span> .'<br/>';
Program 3.
Title: Print out all the "daffodil numbers". The so-called "narcissus number" refers to a three-digit number A number whose sum of cubes is equal to the number itself.
<span> 1</span> <span>$j</span> = 0; <span>//</span><span> 数的个位 </span> <span> 2</span> <span>$k</span> = 0; <span>//</span><span> 数的十位</span> <span> 3</span> <span>$l</span> = 0; <span>//</span><span> 数的百位</span> <span> 4</span> <span>for</span>(<span>$i</span> = 100; <span>$i</span><1000; <span>$i</span>++<span>){ </span><span> 5</span> <span>$j</span> = <span>$i</span> % 10<span>; </span><span> 6</span> <span>$k</span> = (<span>$i</span> % 100 - <span>$j</span>) / 10<span>; </span><span> 7</span> <span>$l</span> = (<span>$i</span> - <span>$i</span> % 100) / 100<span>; </span><span> 8</span> <span>if</span> (<span>$i</span> == (<span>$j</span>*<span>$j</span>*<span>$j</span> + <span>$k</span>*<span>$k</span>*<span>$k</span> + <span>$l</span>*<span>$l</span>*<span>$l</span><span>)) { </span><span> 9</span> <span>echo</span> <span>$i</span> . ' '<span>; </span><span>10</span> <span> } </span><span>11</span> }
Program 4.
Title: Monkey eating peach problem: The monkey picked a few peaches on the first day, ate half of them immediately, and then Not satisfied, I ate another peach, and the next morning I ate half of the remaining peaches and ate another one. From then on, every morning I ate half and one of the leftovers from the previous day. When I wanted to eat more on the morning of the 10th day, there was only one peach left. Find out how many were picked on the first day. (Use reverse thinking and push forward from back)
<span>1</span> <span>$sum</span> = 1<span>; </span><span>2</span> <span>for</span> (<span>$i</span> = 1; <span>$i</span> <= 10; <span>$i</span>++<span>) { </span><span>3</span> <span>$sum</span> = (<span>$sum</span> + 1) * 2<span>; </span><span>4</span> <span>} </span><span>5</span> <span>echo</span> '桃子总数:' .<span>$sum</span>. '<br/>';
Program 5.
Question: There is a sequence of fractions: 2/1, 3/2, 5/3, 8/5, 13 /8, 21/13... Find the sum of the first 20 terms of this sequence. (Pay attention to the changing rules of the numerator and denominator)
<span>1</span> <span>$sum2</span> = 0<span>; </span><span>2</span> <span>$a</span> = 2<span>; </span><span>3</span> <span>$b</span> = 1<span>; </span><span>4</span> <span>for</span>(<span>$i</span> = 1; <span>$i</span> <= 20; <span>$i</span>++<span>) { </span><span>5</span> <span>$sum2</span> = <span>$sum2</span> + <span>$a</span>/<span>$b</span><span>; </span><span>6</span> <span>$b</span> = <span>$a</span><span>; </span><span>7</span> <span>$a</span> += <span>$b</span><span>; </span><span>8</span> <span>} </span><span>9</span> <span>echo</span> '前20项之和为:' .<span>$sum2</span>.'<br/>';

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.
