首页 > 代码库 > Python学习之路(2017.7.16)

Python学习之路(2017.7.16)

# -*- coding:utf-8 -*-
# Author : floatlive

name = input("name:")
age = int(input("age:")) #integer

print(type(age) , type(str(age)) )

job = input("job:")
salary = input("salary:")

info = ‘‘‘
—————— info of %s ——————
Name:%s
Age:%d
Job:%s
Salary:%s
‘‘‘ % (name,name,age,job,salary)

print(info)

info2 = ‘‘‘
——————info of {_name}——————
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
‘‘‘.format(_name=name,
_age=age,
_job=job,
_salary=salary)

print(info2)

info3 = ‘‘‘
——————info of {0}——————
Name:{0}
Age:{1}
Job:{2}
Salary:{3}
‘‘‘.format(name,age,job,salary)

print(info3)

# %s 文本
# %d 整数
# %f 浮点数

——————————————————————————————————————————————————————————————————————————————————————
# -*- coding:utf-8 -*-
# Author : floatlive

age_of_oldboy = 56
count = 0
while count < 3:
guess_age = int(input("guess age:") )
if guess_age == age_of_oldboy:
print("yes,you get it.")
break
elif guess_age < age_of_oldboy:
print("too smaller")
else:
print("too bigger")
count += 1
else:
print("you have tried too many times...fuck off")
——————————————————————————————————————————————————————————————————————————————————————
# -*- coding:utf-8 -*-
# Author : floatlive

age_of_oldboy = 56
count = 0
while count < 3:
guess_age = int(input("guess age:") )
if guess_age == age_of_oldboy:
print("yes,you get it.")
break
elif guess_age < age_of_oldboy:
print("too smaller")
else:
print("too bigger")
count += 1
if count == 3:
count_confirm = input("do you want to keep guessing..?")
if count_confirm != ‘n‘:
count = 0
#else:
# print("you have tried too many times...fuck off")
——————————————————————————————————————————————————————————————————————————————————————
# -*- coding:utf-8 -*-
# Author : floatlive
import getpass

_username = "fuju"
_password = "abc123"
username = input("username:")
#password = getpass.getpass("password:") getpass在pycharm中出错,可在cmd中运行该py
password = input("passsword:")

if _username == username and _password == password:
print("Welcome to {name} login...".format(name=username))
else:
print("Invalid username or password !")

# print("dddd") IndentationError缩进错误,必须顶格
——————————————————————————————————————————————————————————————————————————————————————
# -*- coding:utf-8 -*-
# Author : floatlive

‘‘‘
count = 0
while True:
count = count + 1 # count +=1
print(count)
if count == 1000:
break #结束本次循环

for i in range(10):
print("loop ",i)

for i in range(0,10,2):
print("loop",i)

for i in range(0,10,3):
print("loop",i)


for i in range(10):
if i < 3 :
print("loop",i)
else :
continue #跳出本次循环进入下一循环
print(‘hehe‘)

‘‘‘

for i in range(10):
print("——————————",i)


Python学习之路(2017.7.16)