一、变量引用
#!/usr/bin/env python
# coding: UTF-8

name = 'xk'
age = 27
job = 'it'
info='''
name: %s
age: %s
job: %s
''' %(name, age, job)
print(info)

==============================================

name: xk
age: 27
job: it

==============================

2、wile循环

#!/usr/bin/env python
# coding: UTF-8


age = 27
count = 0
while count < 3:
guess_age = int(input("guess age: "))
if guess_age == age:
print("you got it!")
break
elif guess_age > age:
print("guess smaller!")
else:
print("guess bigger!")
count += 1
if count == 3:
confirm = input("do you want try agein?")
if confirm != "n" or confirm != "N":
count = 0
else:
print("you try too mana times")

3、for循环

#!/usr/bin/env python
# coding: UTF-8

age = 27
for i in range(3):
guess1_age = int(input("please input your guess age: "))
if guess1_age == age:
print("you are good!")
break
elif guess1_age > age:
print("guess smaller!")
else:
print("guess bigger!")
else:
print("mana times!!!!!!!!!!!")

 

posted on 2017-02-26 13:52  昔日未来  阅读(2584)  评论(0编辑  收藏  举报