Self taught journal sharing of python

Keywords: Python Windows

Registration on April 22, 2019

Class notes April 8, 2019

In windows environment, write the first program "hello world" with python

1 print("Hello World!!!")

 

Class notes April 12, 2019

In windows environment, write the first user interaction program "input" with python

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

 

 

Class notes April 13, 2019

python program < digital ratio size >: user input 3 numbers, output the largest number and the smallest number

 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)

 

Class notes April 14, 2019

Four operators of python: arithmetic operator, assignment operator, comparison operator and logical operator.

Arithmetic operators: +, -, *, /, / /,%**

Assignment operator: word="hello" (assignment string), word=23 (assignment number)

Comparison operators: <, >, = ==

Logical operators: not, and, or

 

Class notes April 15, 2019

while statement: print 1-10

1 #Print 1=10
2 No = 1
3  
4 while No<=10:
5      print(No)
6      No+=1

 

Class notes April 16, 2019

1. Write a program to guess the age

 1 #Guess young
 2 
 3 ''' use if Sentence judgement
 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 #utilize while Implement constant input
17 '''
18 Two problems cannot be realized temporarily:
19 1.After entering two numbers (34, 89) from the wrong number, it is unable to remind the user to enter the number in (34, 89)-89)Guess between numbers)
20     2019.4.22 No. has been solved by itself
21 2.It is up to the user to give up guessing and exit the program
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: #Judge whether the input number is correct
35         print()
36         if guess_age>guess_minage: #Used to get the minimum value after input
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: #Used to get the maximum value after input
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: #Want to let users choose to give up, no idea for the moment
47         break #Ditto
48     guess_age=int(input("you can input 'give up' go to out or guess again:"))
49     
50 print("you got it")

 

2. Output even between 1-100

1 #Input 1-100 Even number between
2 
3 No=1
4 
5 while No<=100:
6     if No%2==0:
7         print(No)
8     No+=1

 

3. Syntax 1: break is used to jump out of the loop, and continue is used to end the loop.

Syntax 2: print("abc", end = "") "abc" will continue to display the printed content without wrapping.

Syntax 3: when... Else... Non break programs will execute the programs after else.

 

Class notes April 19, 2019

Compiling multiplication table

 1 '''
 2 Personal thoughts:
 3 Multiplication table. 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'It is line wrap.'\t'yes tab
12         wieth+=1
13     print()
14     high+=1

Posted by Ree on Sun, 24 Nov 2019 14:25:26 -0800