主题是python的相关内容。学python主要是因为感觉国内现在Python缺口比较大,给的薪资较高。
自己的基础不是很牢,权当是从头学pyhton吧。
正文开始
DAY(一)
第一个程序
字符串拼接-StringContenation
# encoding: utf-8
'''@author: ccq@file: StringConcatenation.py@time: 2019/5/19 10:09'''# 字符串拼接及格式化输出name = 'ccq'job = 'college student'age = '21'# format的第一种输出格式info1 = "This is info1. Hi,i'am {0}. my age is {1} and i am a {2}.".format(name, job, age)print(info1)# format的第二种输出格式info2 = "This is info2. Hi,i'am {_name}. my age is {_job} and i am a {_age}.".format(_name=name, _job=job, _age=age)print(info2)# 格式化输出hobby = input("hobby:")info3 = '''------------- info of {_name} -------------job:{_job}age:{_age}hobby:{_hobby}'''.format(_name=name, _job=job, _age=age, _hobby=hobby)print(info3)#pyhton的输出格式还有很多,比如%s的格式,但是感觉format的格式更好用也更清晰,所以这里主要记录了format格式==========================================分割线======================================
第二个程序
明文密文-Ciphertext
# encoding: utf-8
'''@author: ccq@file: Ciphertext.py@time: 2019/5/19 10:32'''# 明文和密文import getpass# 明文username1=input('username:')password1=input('password:')print(username1+'\n'+password1)# 密文 python中可以用,pycharm里不可以用username2=input('username:')password2=getpass.getpass('password:')print(username2+'\n'+password2)#权当了解,import 模块==========================================分割线======================================
第三个程序
ifelse循环-ifelse_password
# encoding: utf-8
'''@author: ccq@file: Ifelse_password.py@time: 2019/5/19 10:41'''# if else循环控制流判断用户名密码username1 = 'ccq'password1 = '123'username2 = input('username:')password2 = input('password:')if username1 == username2: if password1==password2: print('Welcome user {name} to use the computer'.format(name=username1)) else: print("Invalid password , please input password again!")else: print("Invalid username ,please input username again!")#python对代码格式要求很严,个人觉得这有优势也有劣势。优势在于 对程序员编码要求很严,这样对编码规范很有好处,同时也便于阅读。劣势在于 代码较长的时候没有{}易于判断。==========================================分割线======================================
第四个程序
For循环-forloop
# encoding: utf-8
'''@author: ccq@file: ForLoop.py@time: 2019/5/19 15:10'''# For循环for i in range(2,10,2): print("loop:",i)#pyhton的for循环和其他语言的很不相同,习惯起来有些难度==========================================分割线======================================
第五个程序
while循环-while_guessage
# encoding: utf-8
'''@author: ccq@file: While_guessage.py@time: 2019/5/19 11:04'''# 使用while循环猜年龄大小trueage = 21count=0while count<3: age = int(input("please guess the age:")) if age == trueage: print("congratulations! you already guessed the true age") break elif age > trueage: print("too old for me!think yonger!") else: print("too yong for me!think older!") count += 1else: print("you are too foolish to guess my age! fuck off!")#pyhthon的while循环和java比较相同。但是pyhton的else语句挺强大。目前看来是个很好用的东西。比如第五个程序的最后两行。---------------------