python pre-school basics
1. Download and install python3 ( https:
/
/
www.python.org
/
downloads
/
), the default installation
2. Configure Environment Variables【右键计算机】
-
-
》【属性】
-
-
》【高级系统设置】
-
-
》【高级】
-
-
》【环境变量】
-
-
》【在第二个内容框中找到 变量名为Path 的一行,双击】
-
-
> 【Python安装目录追加到变值值中】
3. Install pycharm, from the setting - "file and code templates can set the default template.
#_*_coding:utf-8_*_
hello world program
print('hello word!') #输出:hello word!
variable
Variable names can not be digital initials
Variables are made to be assigned, it points to a specific memory address memory
= NAME1 ' python ' NAME2 = NAME1 NAME1 = ' Java ' Print (NAME2) # output is python
Three kinds of multi-line format output
1.
name = input('please input your name:') age = input('please input your age:') job = input('please input your job:') salary = input('please input your salary:') info = ''' -------------info of %s------------ name:%s age:%s job:%s salary:%s'''%(name,name,age,job,salary) print(info)
2.
name = input('username:') age = input('age:') salary = input('salary:') info =''' ------------------name is {_name}---------------- username:{_name} age:{_age} salary:{_salary} '''.format(_name = name,_age = age,_salary = salary) print(info)
3.
name = input('username:') age = input('age:') salary = input('salary:') info =''' ------------------name is {0}---------------- username:{0} age:{1} salary:{2} '''.format(name,age,salary) print(info)
Additional knowledge base day1 python
The python can not be two completely different things together but can be doubled by an integer such as:
Print ( ' L Love Money ' +5) # output is a fail Print ( ' L Love Money ' * 5) # output 5 times i love money
However, the string is spliced such as:
Print ( ' S ' + ' PAM ' ) # output is a spam
python basis day1 exercises and answers
1. require user input values 0-100, the printing is less than 50 'to lose you' if more than 50 print 'you mistyped'
INPUT = NUM ( ' Please you INPUT Number 0-100: ' ) NUM = int (NUM) IF NUM <= 50 : Print ( " you lose the right ' ) the else : Print ( " you mistyped ' )
2. three chances to guess the age, the age of '23' to guess a little older has prompted a 'young', 'old'
_age = '23' count = 0 while True: if count == 3: break age = input('guess age:') if age > _age : print('old') elif age < _age : print('young') else: print('good work!') break count = count +1
3. Write the login procedure, the user has entered incorrectly three times more than three times the opportunity to enter the wrong lock, enter the password is not visible
name = 'python' key = '123@intel' count = 0 while True: username = input('username:') password = input('password:') if count < 3: if username == name and password == key : print('welcome user %s'%(name)) else: print('invalid username or password!') count +=1 else: print('you have been locked!')
--- end --- restore content
--- end --- restore content