自学python的日记分享

2021年11月25日 阅读数:3
这篇文章主要向大家介绍自学python的日记分享,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

2019.4.22登记python

课堂笔记 2019.4.8windows

在windows环境下,用python写出第一个程序“hello world”ide

1 print("Hello World!!!")
View Code

 

课堂笔记 2019.4.12idea

在windows环境下,用python写出第一个用户交互程序“input”spa

 1 death_age=120
 2 
 3 print("game star")
 4 print("")
 5 print("")
 6 
 7 name=input("input your name:")
 8 age=input("input your age:")
 9 
10 
11 print(name,"still able to live",death_age-int(age),"years")
View Code

 

 

课堂笔记2019.4.13code

python程序<数字比大小>: 用户输入3个数字,输出最大的数字和最小的数字blog

 1 #My idea
 2 
 3 '''
 4 No1=int(input("please input first number:"))
 5 No2=int(input("please input scend number:"))
 6 No3=int(input("please input third number:"))
 7 
 8 if No1>No2>No3:
 9     print("Max No is No1:",No1,"Min No is No3:",No3)
10 elif No1>No3>No2:
11     print("Max No is No1:",No1,"Min No is No2:",No2)
12 elif No2>No1>No3:
13     print("Max No is No2:",No2,"Min No is No3:",No3)
14 elif No2>No3>No1:
15     print("Max No is No2:",No2,"Min No is No1:",No1)
16 elif No3>No1>No2:
17     print("Max No is No3:",No3,"Min No is No2:",No2)
18 elif No3>No2>No1:
19     print("Max No is No3:",No3,"Min No is No1:",No1)
20 '''
21 
22 
23 #teather's idea. only MaxNo,no MinNo
24 
25 '''
26 No1=int(input("please input first number:"))
27 No2=int(input("please input scend number:"))
28 No3=int(input("please input third number:"))
29 
30 No=0
31 
32 if No1>No2:
33     No=No1
34     if No>No3:
35         print("Max No is:",No)
36     else:
37         print("Max No is:",No3)
38 else:
39     No=No2
40     if No>No3:
41         print("Max No is:",No)
42     else:
43         print("Max No is:",No3)
44 '''
45 
46 #bettet idea
47 
48 No1=int(input("please input first number:"))
49 No2=int(input("please input scend number:"))
50 No3=int(input("please input third number:"))
51 
52 max_No=0
53 min_No=0
54 
55 if No1>No2:
56     max_No=No1
57     if max_No<No3:
58         min_No=No2
59         print("Max No is:",No3,"Min No is:",min_No)
60     else:
61         if No2<No3:
62             min_No=No2
63             print("Max No is:",max_No,"Min No is:",min_No)
64         else:
65             min_No=No3
66             print("Max No is:",max_No,"Min No is:",min_No)
67 else:
68     max_No=No2
69     if max_No<No3:
70         min_No=No1
71         print("Max No is:",No3,"Min No is:",min_No)
72     else:
73         if No1<No3:
74             min_No=No1
75             print("Max No is:",max_No,"Min No is:",min_No)
76         else:
77             min_No=No3
78             print("Max No is:",max_No,"Min No is:",min_No)
View Code

 

课堂笔记2019.4.14字符串

python的四种运算符:算数运算符,赋值运算符,比较运算符,逻辑运算符。input

算数运算符:+,-,*,/,//,%,**it

赋值运算符:word="hello"(赋值字符串) , word=23(赋值数字)

比较运算符:<,>,==,!=

逻辑运算符:not , and , or (and和or有短路原则,若是条件1结果已知,后续代码再也不执行)

 

课堂笔记2019.4.15

while语句:打印1-10

1 #打印1=10
2 No = 1
3  
4 while No<=10:
5      print(No)
6      No+=1
View Code

 

课堂笔记2019.4.16

1.编写一个猜想年龄的程序

 1 #猜年轻
 2 
 3 ''' 用if语句判断
 4 goal_age=76
 5 
 6 guess_age=int(input("please guess age(1-100):"))
 7 
 8 # print(guess_age,goal_age)
 9 
10 if(guess_age==goal_age):
11  print("you got it")
12 else:
13  print("sorry,you are wrong")
14 '''
15 
16 #利用while实现一直输入
17 '''
18 暂时没法实现2个问题:
19 1.从输错了数字开始算起的区间(好比输入两个数字(34,89)后,没法提醒在(34-89)之间的数字猜想)
20     2019.4.22号已自行解决
21 2.由用户本身选择放弃猜想退出程序. 2019.5.6 已解决
22 
23 '''
24 goal_age = 76
25 
26 guess_age = int(input("please guess age(1-100):"))
27 guess_maxage = 100
28 guess_minage = 1
29 
30 while guess_age != goal_age:
31 
32     if guess_age < goal_age:  # 判断输入的数字是否正确
33         print()
34         if guess_age > guess_minage:  # 用来取输入后的最小值
35             guess_minage = guess_age
36         print("your input number is:", guess_age)
37         print("that's too small... please guess ", guess_minage, "- ", guess_maxage, "!!")
38     elif guess_age > goal_age:
39         print()
40         if guess_age < guess_maxage:  # 用来取输入后的最大值
41             guess_maxage = guess_age
42         print("your input number is:", guess_age)
43         print("that's too big... please guess ", guess_minage, " -", guess_maxage, "!!")
44 
45     guess_age = input("you can input 'give up' go to out or guess again:")
46 
47         if guess_age == "give up":
48         print("It's so pity!!!")
49         break
50 
51     guess_age = int(guess_age)
52 
53 else:
54     print("you got it")
View Code

 

2.输出1-100之间的偶数

1 #输入1-100之间的偶数
2 
3 No=1
4 
5 while No<=100:
6     if No%2==0:
7         print(No)
8     No+=1
View Code

 

3.语法1:break 用来跳出本循环,continue用来结束本次循环。

   语法2:print(“abc”,end=“”) “abc”后面不换行,继续显示打印的内容。

 语法3:while ... else... 非break停止的程序,都会执行else后的程序 。

 

课堂笔记2019.4.19

编写九九乘法表

 1 '''
 2 我的思路:
 3 九九乘法表。 a=1  while a <= 9: b=1  while b<=a:print((b,”*”,a,b*a),end(“,”))   b+=1  a+=1
 4 '''
 5 
 6 high =1
 7 
 8 while high<=9:
 9     wieth=1
10     while wieth<=high:
11         print(wieth,"*",high,"=",wieth*high,end="\t") # '\n'是换行,'\t'是tab
12         wieth+=1
13     print()
14     high+=1
View Code