首页 文章 精选 留言 我的

精选列表

搜索[基础],共10000篇文章
优秀的个人博客,低调大师

Python零基础学习笔记(三)——注释、输入和输出

单行注释# """多行注释多行注释......""" '''多行注释多行注释......'''print 打印到屏幕上一些信息,内容就是“”之间的print("这是第一个关于注释的文件") 2 .打印多个字符转,用逗号隔开,但遇到逗号会输出一个空格print("我","是","谁") 可以运算print(10 + 8) print("10 + 8 =", 10 + 8)input 从外部获取变量的值等待输入(阻塞),输入之后继续执行例:age = input("请输入你的年龄:")print("我看到你的年龄是", age, "岁") (以上所有程序) (程序执行结果)

优秀的个人博客,低调大师

Zabbix4.0 for PostgreSQL (上篇):基础环境的搭建部署

概述 Zabbix大家都很熟悉,一般的是使用MySQL作为存储库来使用的,而我看使用手册上是使用postgresql也是可以的,所以就做了一次基于pg的zabbix搭建测试,记录下来,分享给大家 Server端配置 配置PG环境 安装好pg,且在root和postgres下都配置好pg的环境变量,以供后续使用 在hba控制文件中直接加入这一行 host zabbix zabbix 192.168.0.0/24 trust host all all 127.0.0.1/32 md5 配置apache 创建user [root@Zabbix_GW_TEST opt]# adduser apache 准备好安装包并解压 [root@Zabbix_GW_TEST opt]# ls httpd-2.4.37.tar.gz httpd-2.4.37.tar.gz [root@Zabbix_GW_TEST opt]# tar -xvzf httpd-2.4.37.tar.gz 编译安装 执行编译命令 [root@Zabbix_GW_TEST httpd-2.4.37]# ./configure --prefix=/usr/local/apache --enable-rewrite --enable-deflate --enable-expires --enable-headers --enable-modules=most --with-mpm=worker --enable-so 报错: configure: error: APR not found. Please read the documentation. 解决: yum install apr yum install apr-util-devel 报错: configure: error: in `/opt/httpd-2.4.37': configure: error: C compiler cannot create executables See `config.log' for more details 解决: yum install gcc 问题: configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ 解决: yum -y install pcre-devel 问题: configure: error: mod_deflate has been requested but can not be built due to prerequisite failures 解决: yum install -y zlib-devel 以下画面说明编译成功 configure: summary of build options: Server Version: 2.4.37 Install prefix: /usr/local/apache C compiler: gcc -std=gnu99 CFLAGS: -pthread CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE LDFLAGS: LIBS: C preprocessor: gcc -E 继续安装 gmake gmake install 安装成功之后安装目录也就生成文件了 [root@Zabbix_GW_TEST apache]# ls bin build cgi-bin conf error htdocs icons include logs man manual modules 建立脚本根目录 用来存放html信息 mkdir /home/www chown -R apache:apache /home/www 配置运行参数 [root@nfs httpd-2.2.31]# vim /usr/local/apache/conf/httpd.conf #监听port Listen 80 #运营apache服务的用户及用户组,为apache User apache Group apache #管理员的邮箱是 ServerAdmin 1058582934@qq.com #配置脚本根目录 DocumentRoot "/home/www" #配置 ServerName 127.0.0.1:80 <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow allow from all </Directory> <Directory "/home/www"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> 配置环境变量 添加一行环境变量到文件中 export PATH=/usr/local/apache/bin:$PATH [root@Zabbix_GW_TEST apache]# source ~/.bash_profile [root@Zabbix_GW_TEST apache]# which apachectl /usr/local/apache/bin/apachectl 启动apache服务 apachectl start 顺便配置开机自动 vim /etc/rc.d/rc.local /usr/local/apache/bin/apachectl start 至此,Apache配置完成 安装配置php 安装php依赖包 wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar zxf libiconv-1.14.tar.gz ./configure --prefix=/usr/local/libiconv make make install 准备好包并解压 tar -xvzf php-5.5.38.tar.gz 编译 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv --enable-short-tags --enable-sockets --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir --with-pgsql=/usr/postgresql --enable-fpm --enable-bcmath --with-gettext 报错 Sorry, I cannot run apxs. Possible reasons follow: 1. Perl is not installed 2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs 3. Apache was not built using --enable-so (the apxs usage page is displayed) The output of /usr/local/apache/bin/apxs follows: ./configure: /usr/local/apache/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory configure: error: Aborting 解决:将apache的bin文件下的apxs文件第一行改为 #!/usr/bin/perl -w 报错: configure: error: xml2-config not found. Please check your libxml2 installation yum install libxml2-devel 报错 configure: error: Cannot find OpenSSL's <evp.h> yum install openssl openssl-devel 报错 configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/ yum install curl curl-devel 报错 configure: error: There is something wrong. Please check config.log for more information. curl-devel-7.15.5-2.el5安装 报错 configure: error: jpeglib.h not found. yum -y install libjpeg-devel 报错 configure: error: png.h not found. yum install libpng libpng-devel 报错: configure: error: freetype-config not found. yum install freetype-devel 报错 configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution yum -y install libxslt libxslt-devel 显示如下,则编译完成 creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands 安装 make make install 准备配置文件 [root@Zabbix_GW_TEST php-5.5.38]# cp php.ini-development /usr/local/php/lib/php.ini [root@Zabbix_GW_TEST php-5.5.38]# vi /usr/local/php/lib/php.ini 修改配置文件 [root@nfs php-5.5.38]# cp php.ini-development /usr/local/php/lib/php.ini [root@nfs php-5.5.38]# vim /usr/local/php/lib/php.ini error_reporting = E_ALL & ~E_NOTICE #报告所有的错误,但除了E_NOTICE这一种 display_errors = On #在终端显示出错信息,这个在生产环境最好设置成off track_errors = Off #是否在变量$php_errormsg中保存最近一个错误或警告消息 post_max_size = 16M #表单最大提交的数据量大小 upload_max_filesize = 16M #准许上传文件大小限制为16M date.timezone = PRC #中华人民共和国时区 expose_php = Off #隐藏php版本信息 curl -I www.ha97.com HTTP/1.1 200 OK Server: nginx Date: Tue, 20 Jul 2010 05:45:13 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding #已经彻底隐藏了PHP版本。 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20121212/" #扩展模块存放目录 修改Apache的文件,在重启 [root@nfs php-5.5.38]# vim /usr/local/apache/conf/httpd.conf 增加下面内容 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> <IfModule mime_module> AddType application/x-httpd-php-source .phps AddType application/x-httpd-php .php .phtml </IfModule> 换一个思路的nginx搭建 概述 在apache配置解析php的操作种,遇到种种坑,Apache的配置不太熟悉,界面打不开php文件,理论上问题是出在Apache配置访问php上。但是我能力有限,解决不来,所以就换一个NGINX试试。 编译安装 上传解压,并编译。NGINX的编译相对简单,就不做详细记录 tar -xvzf nginx-1.6.0.tar.gz cd nginx-1.6.0 ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module make make install 配置NGINX访问PHP 这个是NGINX的关键,因为zabbix的界面全部都是PHP语言写的,必须使用PHP软件才能解析应用 server { listen 80; server_name localhost; location ~ \.(php|php5)?$ { root /data/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/html$fastcgi_script_name; include fastcgi_params; } location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ { root /data/html; } } 配置nginx.conf文件。增加两个location,第一个location增加的是站点的地址信息。第二个是增加解析各种图片样式的功能(因为在没有加的时候,我打开的zabbix界面全部都是只有文字,没有任何图片与样式,如下。原因就是PHP没有解析这些内容) 创建好站点目录 浏览器通过端口来访问服务器的文件,并用解析器解析,我们需要先准备好这些文件。zabbix的PHP文件是放在源码包里的,解压后就可以看到可以在上面的配置文件中可以看到我已经选择了/data/html cp -r /opt/zabbix-4.0.2/frontends/php/* /data/html 注意赋权 启动nginx 把环境变量配置在root下 export PATH=/usr/local/nginx/sbin:$PATH 启动nginx,没有报错则启动成功,看监听端口和后台进程 [root@Zabbix_GW_TEST ~]# netstat -lnp|grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25373/nginx: master [root@Zabbix_GW_TEST ~]# ps -ef|grep nginx root 12817 10266 0 18:11 pts/1 00:00:00 grep --color=auto nginx root 25373 1 0 01:21 ? 00:00:00 nginx: master process nginx www 27717 25373 0 02:07 ? 00:00:00 nginx: worker process Zabbix配置 用户环境配置好 用户 adduser zabbix 编译zabbix 编译 ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-postgresql=/usr/local/pgsql/bin/pg_config --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv 安装依赖 yum install net-snmp-devel yum install libssh2-devel yum install OpenIPMI-devel yum install openldap-devel yum install libevent-devel yum install curl-devel 编译到此界面则安装成功 *********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * <http://www.zabbix.com> * *********************************************************** 执行make install 配置好环境变量 将此行写进配置文件中 PATH=/usr/local/zabbix/bin:/usr/local/zabbix/sbin:$PATH 创建zabbix 数据库 postgres=# create role zabbix login postgres-# ; CREATE ROLE postgres=# \password zabbix Enter new password: Enter it again: postgres=# create database zabbix with template template0 encoding 'UTF8' ; CREATE DATABASE postgres=# grant all on database zabbix to zabbix; GRANT postgres=# \q 导入zabbix数据 在源码下,有zabbix数据库的数据 cd /opt/zabbix-4.0.2/database/postgresql/ psql -Uzabbix -dzabbix -h127.0.0.1 -f schema.sql psql -Uzabbix -dzabbix -h127.0.0.1 -f images.sql psql -Uzabbix -dzabbix -h127.0.0.1 -f data.sql 配置zabbix_server参数 [root@Zabbix_GW_server ~]# vim /usr/local/zabbix/etc/zabbix_server.conf #监听port ListenPort=10051 #日志存放地点及大小 LogFile=/tmp/zabbix_server.log LogFileSize=10 #pid文件存放地点 PidFile=/tmp/zabbix_server.pid #下面几个参数是配置数据库连接参数 DBHost=127.0.0.1 DBName=zabbix DBUser=zabbix DBPassword=zabbix DBPort=5432 #监听ip范围 ListenIP=0.0.0.0 #media types中使用script存放目录 AlertScriptsPath=/usr/local/zabbix/alertscripts 启动服务 zabbix_server 查看是否有错,就查看zabbix_server 的启动日志,如果有报错,按照报错修改。反正我安装的时候真的报错频出,经历过,懂得都懂 查看web界面 此时就可以通过web界面来访问zabbix了输入地址 可以看到,配存在一些问题也还是需要修改的,不然的话无法安装 agent端配置 概述 agnet端就是被监控的数据库主机,也是需要做一些安装 创建用户 groupadd zabbix useradd -g zabbix -s /sbin/nologin zabbix 编译安装 ./configure --prefix=/usr/local/zabbix-agent --enable-agent make install 无需指定其他的编译参数 修改配置文件 vi /usr/local/zabbix-agent/etc/zabbix_agentd.conf LogFile=/tmp/zabbix_agentd.log Server=192.168.6.17/32 Hostname=Zabbix agent 配置到环境变量 PATH=/usr/local/zabbix-agent/bin:/usr/local/zabbix-agent/sbin:$PATH 启动zabbix_agent 直接运行zabbix_agent命令,查看日志,观察是否正常 至此 至此,zabbix的基本配置完成。后续还要配置监控等操作。后面慢慢再说

优秀的个人博客,低调大师

JavaScript 基础--- (正则表达式 / 事件监听与绑定)

正则表达式 创建正则表达式: 方法一: var reg = /pattern/; 方法二:var reg = new RegExp('pattern'); RegExp 对象的常用方法: 示例: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> var str = 'awddsafasei'; var reg = new RegExp('weiwel'); var reg = /weiwei/; //正则表达式中有两个方法 exec() :返回,符合条件的字符串 test(): alert(reg.exec(str)); alert(reg.test(str)); </script> </head> <body> </body> </html> 输出: 2.正则表达式所支持的常用通配符 3.正则表达式量词 4.正则表达式修饰符 案例: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> var str = 'awddsafasei'; var reg = /^a(\w){2,}i$/g; //正则表达式中有两个方法 exec() :返回,符合条件的字符串 test(): alert(reg.exec(str)); alert(reg.test(str)); </script> </head> <body> </body> </html> 输出: 事件绑定 HTML 事件: 示例:点击按钮,弹出警示框 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="button" id="button1" value="button1"/> </body> <script type="text/javascript"> document.getElementById("button1").onclick = fun; function fun(){ alert('hello'); } </script> </html> 输出:点击---弹出 事件监听 使用返回值改变 HTML 元素的默认行为(可以通过在绑定事件中加上 return false 来阻止其默认行为) 通用性的事件监听方法: 1.绑定 HTML 元素属性 <input type ="button" value="click" onclick="check(this)"/ > 2.绑定 DOM 对象属性 document.getElementById("btn1").onclick=test; 推荐尽量采用与浏览器无关的事件绑定方法,保证有更好的跨浏览器特性 标准DOM中的事件监听方法: 1.[object].addEventListener("事件类型","处理函数","冒泡事件或捕获事件") 2.[object].removeEventListener("事件类型","处理函数","冒泡事件或捕获事件") 案例: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="text" id="username" value="" /> <div id="div1" style="width:100px;height: 50px;background: red;"> <input type="button" id="button1" value="button1"/> </div> </body> <script type="text/javascript"> var username = document.getElementById("username"); /*username.addEventListener("focus",function(){ alert('focus'); }) */ // 获取焦点弹出警示框 username.onblur = function(){ alert('blur'); } //焦点消失弹出警示框 var btn = document.getElementById("button1"); var div1 = document.getElementById("div1"); btn.addEventListener("click",btnclick); function btnclick(){ alert('button'); } div1.addEventListener("click",function(){ alert('div1'); },false); div1.addEventListener("mouseout",function(){ alert('mousedo'); }) //鼠标移入 div1 中就弹出警示框 </script> </html> 输出:点击、获取焦点,失去焦点,鼠标移入红色区域均弹出警示框 、 综合案例:注册验证 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <form action="" method="post"> 用户名:<input type="text" id="username" onchange="checkUn()"/> <span id="unspan" style="color: red;"> </span><br /> 密码:<input type="text" id="password"/><br /> 手机号:<input type="text" id="phone" onchange="checkPhone()"/> <span id="phonespan" style="color: red;"> </span> <br /> 邮箱:<input type="text" id="email" onchange="checkEmail()"/> <span id="emailspan" style="color: red;"> </span> <br /> <input type="submit" value="提交"/> </form> </body> <script type="text/javascript"> //校验用户名 function checkUn(){ var reg = /(\w){4,}/ var username = document.getElementById("username").value; if(!reg.test(username)){ document.getElementById('unspan').innerHTML = '用户名最少四个字符'; }else{ document.getElementById('unspan').innerHTML = ''; } } function checkPhone(){ //15944556789 var reg = /^1[3578](\d){9}/; var phone = document.getElementById("phone").value; if(!reg.test(phone)){ document.getElementById('phonespan').innerHTML = '手机号格式不正确'; }else{ document.getElementById('phonespan').innerHTML = ''; } } function checkEmail(){ //weiwei234@163.com.cn var reg = /^[a-zA-Z_](\w){2,12}@[a-zA-Z0-9]{2,7}((\.)([a-zA-Z]){2,3}){1,2}$/; var email = document.getElementById("email").value; if(!reg.test(email)){ document.getElementById('emailspan').innerHTML = '邮箱格式不正确'; }else{ document.getElementById('emailspan').innerHTML = ''; } } </script> </html> 输出:

优秀的个人博客,低调大师

学习Java基础知识,打通面试关~十三锁机制

静态创建线程池 我们平常使用的大部分还是依靠java中自带的静态工厂产生的线程池。先了解下自带的线程池。 newFixedThreadPool(int numThreads) 该线程池会在初始化的指定线程数量。具有以下的特点1.在任何时刻都是最多有numThreads的线程数量活动。如果超过限制会在LinkedBlockingQueue中等待。 2.当达到核心线程数的时候,线程数不在继续增加。3.有工作线程退出,新的工作线程被创建来达到设置的线程数。 Executors.newFixedThreadPool(1); //源码实现 public static ExecutorService newFixedThreadPool(int nThreads) { return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); } newCachedThreadPool 该线程池是一个可以用来缓存的线程池。1.尝试缓存使用过的线程。2.没有缓存的线程池时,就会使用工厂方法创建线程池,最大的容量理论上是Integer.MAX_VALUE。这个跟服务器的配置有关。所以如果过来大量的线程任务,那么该线程池会在瞬间创建多个线程来执行工作。3.时间上多余的线程超过60秒会被终止移除缓存中。4.内部使用的SynchronousQueue实现的队列,该队列在实现的时候没有容量。适合来做交换的工作。 Executors.newCachedThreadPool(); //源码实现 public static ExecutorService newCachedThreadPool() { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); } newSingleThreadExecutor 该线程池是用来设置单个的线程池,使用的队列是无界队列。因为提交的任务只要一个是能活动的,剩下的是放到无界队列中。队列是先进先出的。那么执行顺序是有序的。 Executors.newSingleThreadExecutor(); //源码 public static ExecutorService newSingleThreadExecutor() { return new FinalizableDelegatedExecutorService (new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>())); } newWorkStealingPool 工作线程,该线程是在jdk1.8以后新增加的.使用的是ForkJoinPool创建线程池。该任务执行没有顺序。需要考虑到硬件的cpu核心数。 Executors.newWorkStealingPool(); public static ExecutorService newWorkStealingPool() { return new ForkJoinPool (Runtime.getRuntime().availableProcessors(), //默认使用的是硬件的cpu数目 ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); } Executors.newWorkStealingPool(10); public static ExecutorService newWorkStealingPool(int parallelism) { return new ForkJoinPool (parallelism, // 使用的是自定义的核心数 ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); } newSingleThreadScheduledExecutor()与newScheduledThreadPool(int poolSize) 周期性的调度执行任务的线程池。 单个执行。 Executors.newSingleThreadScheduledExecutor(); public static ScheduledExecutorService newSingleThreadScheduledExecutor() { return new DelegatedScheduledExecutorService (new ScheduledThreadPoolExecutor(1)); } //核心周期执行的线程数 Executors.newScheduledThreadPool(10); public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) { return new ScheduledThreadPoolExecutor(corePoolSize); } 了解其java内部的静态线程池,并且在程序中使用其策略。当然在这种我们没有看到的是线程池的拒绝策略。无界队列和有界队列,核心数的与最大的核心数的设置,这些不同。那么我们的执行拒绝策略也是不同的。在接下里的文章我们会具体了解拒绝策略。 原文发布时间为:2018-07-09本文作者:mengrui本文来自云栖社区合作伙伴“LuckQI”,了解相关信息可以关注“LuckQI”。

优秀的个人博客,低调大师

十五道Python小案例,学会这些,Python基础已过关!

十五道Python的小案例,不知道各位都会了多少! 一、猜数字 1到4能组成多少个互不相同且不重复数字的三位数?分别是? 分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。 程序源代码: 二、公司发放的奖金的计算 分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。 程序源代码: 三、一个整数加上100后是一个完全平方数,再加168又是一个完全平方数,请问该数是多少? Python的学习 q-u n 二二七,四三五,四五零 ,是想转行还是想入行都可以来了解一起进步一起学习!内有开发工具,很多干货和技术资料分享!希望新手少走弯路 分析: 程序源代码: 四、输入*年*月*日,判断这一天是这一年的第几天? 分析:以3月5日为例,先把前两月的加起来,再加上5天就是本年的第几天,特殊情况下闰年且输入月份大于2时需考虑多加一天: 程序源代码: 以上实例输出结果为: 五、输入三个整数x,y,z,把这三个数由小到大输出 Python的学习 q-u n 二二七,四三五,四五零 ,是想转行还是想入行都可以来了解一起进步一起学习!内有开发工具,很多干货和技术资料分享!希望新手少走弯路 分析:我们把最小数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,再用x与z进行比较,当x>z则将x与z的值进行交换,这样能使x最小。 程序源代码: 六、斐波那契数列 分析:斐波那契数列(Fibonacci sequence),又称黄金分割数列,指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……。 在数学上,费波那契数列是以递归的方法来定义: 程序源代码: 方法一 方法二 以上实例输出了第10个斐波那契数列,结果为: 55 方法三 以上程序运行输出结果为: [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] 七、将一个列表的数据复制到另一个列表中 程序分析:使用列表[:] 程序源代码: 以上实例输出结果为: [1, 2, 3] 八、输出 9*9 乘法口诀表 分析:分行与列考虑,共9行9列,i控制行,j控制列。 源代码: 以上实例输出结果为: 九、暂停一秒输出 分析:使用 time 模块的 sleep() 函数 程序源代码: 以上实例输出结果为(会有停顿效果): 1 a 2 b 十、暂停一秒输出,并格式化当前时间 源代码: 以上实例输出结果为: 2015-10-21 17:48:40 2015-10-21 17:48:41 十一、有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 程序分析:兔子的规律为数列1,1,2,3,5,8,13,21.... 程序源代码: 以上实例输出结果为: 十二、判断101-200之间有多少个素数,并输出所有素数 分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 代码: 以上实例输出结果为: 十三、打印出所有的"水仙花数" 程序源代码: 以上实例输出结果为: 153 370 371 407 十四、将一个正整数分解质因数 程序源代码: 以上实例输出结果为: 90 = 2 * 3 * 3 * 5 100 = 2 * 2 * 5 * 5 十五、利用条件运算符的嵌套来完成学习成绩计算 学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。 分析:(a>b)?a:b这是条件运算符的基本例子。 代码: 以上实例输出结果为: 输入分数: 89 89 属于 B

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册
修改密码
忘记密码