- 博客(37)
- 资源 (2)
- 收藏
- 关注
原创 操作mysql(利用Python)
本次我们来研究一下用Python操纵mysql数据库。首先,我们来建立一个名为mydb的本地数据库。我们对这个数据库进行相关设置,最终得到下面效果:接着我们打开python进行数据库的连接,代码如下:import pymysqlconfig={ "host":"127.0.0.1", "user":"root", "password":"Aa@123", "database":"mydb"}db = pymysql.connect(**conf.
2021-11-26 22:27:44
194
原创 JAVA小实例(十七)
本实例是实现第n个素数到第m个素数之间(包含n,m)的所有素数的和。代码如下:package test02;import java.util.Scanner;public class Nov22 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入第n个素数"); int n =
2021-11-22 20:16:05
68
原创 JAVA小实例(十六)
本节的实例是一个实现一个数的数字特征值。我写了俩种代码供大家参考:第一个如下:package test02;import java.util.Scanner;public class ShuZi01 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入:"); int numbe
2021-11-19 21:14:49
172
原创 文件与异常(Python)
一.首先我们新建一个文件:file.txt1.我们进行write文件写入操作:f='file.txt'with open(f,'w') as fobj: fobj.write('1\n') fobj.write('2\n') fobj.write('3')接着我们来读取它:f='file.txt'with open(f) as fobj: c=fobj.read()print(c)我们可以看到结果跟我们预想的一样。但我们每次都这样写入
2021-11-17 21:17:52
451
原创 类与对象[二](Python)
首先我们来新建一个类:class Person: def _init_(self,name): self.name=name def say(self): print(self.name) def sum(self,i,j): print(i+j)//类文件名为:cs.py1.我们来导入一下类模块:import csobj=cs.Person('user1')obj.say()obj.sum(1,3)
2021-11-15 20:47:27
640
原创 类与对象[一](Python)
class Cdict: def getkeys(dicts): keys=[] for k in dicts: keys.append(k) return keys def getvals(dicts): vals=[] for k in dicts: vals.append(dicts[k]) return valsdicts={'na.
2021-11-13 23:26:51
541
原创 JAVA小实例(十五)
本次实例是一个信号转换器,代码如下:package test02;import java.util.Scanner;public class XInH { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入个位数"); int g = in.nextInt(); System.out.println("请输入十位数
2021-11-13 21:49:25
193
原创 JAVA小实例(十四)
本次的实例是实现BJT转换为UTC(一个时间转换)代码如下:package test02;import java.util.Scanner;public class TimeT { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入BJT小时"); int BJTH = in.nextInt(); System.out
2021-11-12 23:42:58
359
原创 函数四(Python)
本次我们来研究一下函数中模块的使用我们先来建立一个名为funcs.py的模块。def show(): print('show')def say(): print('say')def eat(): print('eat')//文件名为funcs.py然后我们开始函数中模块的使用。第一,我们先来展示从模块中导入一个函数:from funcs import saysay()//导入模块中的say函数第二,我们来从模块中导入多个函数:..
2021-11-12 21:03:08
374
原创 函数三(Python)
1.global作用tot=10def sum(): global tot tot=tot+1 print(tot)sum()效果如下图所示:2.普通参数与任意字典类型def show(a,b,i,**j): print(a,b,i,j)show(1,2,3,name='user1',age=20)效果如下图所示:3.递归算法i=3tot=0def sum(n): global tot to...
2021-11-08 22:33:43
53
原创 JAVA小实例(十三)
计算多个数的平均数。package test01;import java.util.Scanner;public class Pinjun { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请输入:"); int number; int sum = 0; int count = 0; number = in.nex...
2021-11-07 20:17:44
42
原创 JAVA小实例(十二)
判断一个数是否为素数。package test01;import java.util.Scanner;/* * 判断一个数是否为素数 */public class Sushu { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请输入一个数:"); int n = in.nextInt(); boolean isPrime.
2021-11-07 20:14:08
37
原创 JAVA小实例(十一)
计算:1+1/2+1/3+...+1/npackage test01;import java.util.Scanner;/* * 计算:1+1/2+1/3+...+1/n */public class Leijia01 { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请输入一个数字:"); int n = in.nextI.
2021-11-07 20:07:25
51
原创 JAVA小实例(十)
阶乘用户输入的数字:package test01;import java.util.Scanner;/* * 阶乘 */public class Jiecheng { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请输入要阶乘的数:"); int n = in.nextInt(); int i = 1; i.
2021-11-07 20:01:18
43
原创 JAVA小实例(九)
求俩数的最大公约数(一):package test01;import java.util.Scanner;/* * 求a和b的最大公约数 */public class Gongyue { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请依次输入a和b:"); int a = in.nextInt(); int b =in..
2021-11-07 19:58:22
50
原创 JAVA小实例(八)
把用户输入的数以逆序输出import java.util.Scanner;public class Dushu { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("请输入数字:"); int number = in.nextInt(); int result = 0; do { int digit = number...
2021-11-07 19:52:07
50
原创 JAVA小实例(七)
用户输入一个金额,计算机用小金额拼凑成指定金额package test01;import java.util.Scanner;/* * 凑硬币 */public class Coucoin { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("请输入金额:"); int amount = in.nextInt(); //标
2021-11-07 14:50:08
47
原创 JAVA小实例(六)
由计算机出一个1~100以内的数,用户猜测,计算机提示其偏大还是偏小。package test01;import java.util.Scanner;public class Caishu { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("宝宝,请输入你要猜的数字:"); int number = (int)(Math.random.
2021-11-07 14:45:47
44
原创 函数二(Python)
一、命名参数和字典def show(**i): print(i)show(name='user1',age=20)二、任意多个参数def show(*i): tot=0 for j in i: tot+=j print(tot)show(1,2,3)三、 global把局部变量变成全部变量def sum(): global x x=10sum()print(x)四、实参...
2021-11-05 21:17:43
247
原创 JAVA小实例(五)
多分枝结构在java中也较为常用,今天我们会讲到俩个方法去实现它。第一个就是switch-case方法:public class Switch { public static void main(String[] args){ System.out.println("请输入:"); Scanner in = new Scanner(System.in); int type = in.nextInt(); switch(type){ case 1 : System.
2021-11-02 22:52:58
67
原创 JAVA小实例(四)
package test;import java.util.Scanner;public class BiJiao { public static void main(String[] args){ Scanner in = new Scanner(System.in); int x; int y; int z; System.out.println("请输入三个数:"); x = in.nextInt(); y = in.nextInt(); z = in.ne.
2021-11-02 22:43:20
40
原创 JAVA小实例(三)
package test;import java.util.Scanner;public class WenDu { public static void main(String[] args){ Scanner in = new Scanner(System.in); int F ; int C = 0; System.out.println("请输入摄氏度:"); C = in.nextInt(); System.out..
2021-11-02 22:39:54
37
原创 JAVA小实例(二)
package test;import java.util.Scanner;public class Day01 { public static void main(String[] args){ System.out.println("你好"); Scanner in = new Scanner(System.in); int price; int number; System.out.print("请输入总工资:"); price = in.nextInt();.
2021-11-02 22:37:14
40
原创 JAVA小实例(一)
package test;import java.util.Scanner;public class ChePiao { public static void main(String[] args){ double a = 1.0; double b = 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1; System.out.println(a==b); System.out.println("a="+a+ "b="+b); System..
2021-11-02 22:33:52
53
原创 函数一(Python)
文章开头先来回顾下之前的while循环:1.调用remove删除元素一次只能删除最前面的一个,假如一个列表中有很多个相同元素,这时候我们要想把这个元素都删除掉,就需要调用while函数。如图为代码实现:接着我们进入今天的正题:函数2.函数定义3.函数俩大作用:(1)函数体内的执行代码(2)函数最后返回的值4.pop函数作用:(1)删除列表的最后一个元素(2)返回刚才删除的那个元素的值5.reverse函数作用:(1)对一个列表所有元素进...
2021-11-01 20:31:26
91
原创 用户输入和while循环(Python)
1.函数input的使用2.input获取值为字符串3.求模运算符4.使用while循环5.while死循环6. input+while简单实例7. while循环使用标记8.break语句9.continue语句10.避免死循环11. 移动列表元素实例12.删除列表中特定值13.input填充字典最后,我们来观察这俩组代码,它们有细微的区别,输出结果也不太...
2021-10-29 22:24:39
64
原创 大厂面试精选题
先来看第一个例子:if(3 >0) int a = 90; System.out.println(a);大家可以看到出现了错误,这是哪里错了呢?细细观察,大家可以发现是少了if语句后面的花括号,那我们加上花括号来试试,话不多说,上图。大家可以发现运行正常了。接着大家来看这样一段代码:if (3>0) System.out.println("hello");这里的if语句后面没有花括号,那么大家来猜一猜是否会报错呢?话不多说,上...
2021-10-21 20:27:53
48
3
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人