当前位置: 移动技术网 > IT编程>脚本编程>Python > 自学python的日记分享

自学python的日记分享

2019年04月23日  | 移动技术网IT编程  | 我要评论

5岁儿童教育,养生美白,陈鲁豫 心相约

2019.4.22登记

课堂笔记 2019.4.8

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

1 print("hello world!!!")

 

课堂笔记 2019.4.12

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

 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")

 

 

课堂笔记2019.4.13

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

 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)

 

课堂笔记2019.4.14

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

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

赋值运算符: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

 

课堂笔记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.由用户自己选择放弃猜测退出程序
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 # print(guess_age,goal_age)
31 
32 while guess_age!=goal_age:
33     
34     if guess_age<goal_age: #判断输入的数字是否正确
35         print()
36         if guess_age>guess_minage: #用来取输入后的最小值
37             guess_minage=guess_age
38         print("your input number is:",guess_age)
39         print("that's too small... please guess ",guess_minage,"- ",guess_maxage,"!!") 
40     elif guess_age>goal_age:
41         print()
42         if guess_age<guess_maxage: #用来取输入后的最大值
43             guess_maxage=guess_age
44         print("your input number is:",guess_age)
45         print("that's too big... please guess ",guess_minage," -",guess_maxage,"!!")
46     else: #想用来让用户自行选择放弃,暂时无想法
47         break #同上
48     guess_age=int(input("you can input 'give up' go to out or guess again:"))
49     
50 print("you got it")

 

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

 

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

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网