码迷,mamicode.com
首页 > 编程语言 > 详细

python-day1

时间:2017-10-16 19:47:18      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:ber   range   ==   little   break   try   字符串   real   raw   

在test.log写入字符串类容:
‘‘‘
f = open("test.log","w")
f.write("this is the first line\n")
f.write("this is the second line\n")
f.write("this is the 3 line\n")
f.write("this is the 4 line\n")
‘‘‘
# f = open("test.log","r")
# for line in f:
# if "3" in line:
# print "this is the thrid line"
# else:
# print line,
‘‘‘
f = open("test.log","a")
f.write("6\n")
f.write("7\n")
f.close()
‘‘‘
f = open("test.log","w+")
f.write("new line\n")
print("data:",f.read())
f.close()


输入字符串游戏:
sex = raw_input("input your gender:")
if sex =="girl":
print("I would like to have a little monkey with monkey king ")
print("second line")
elif sex == "man":
print("Going to homesexual!...")
else:
print("Pervert!")
continue循环:
for j in range (5):
for i in range (10):
if i < 5:
continue
if j > 3:
break
print(i)

猜幸运数字游戏:
lucky_num = 10
input_num = 0
while lucky_num != input_num:
input_num = int(input("input your guess lucky_num:"))
#if input_num == lucky_num:
# print("bingo!")
#break
if input_num > lucky_num:
print("the real number to smaller")
elif input_num < lucky_num:
print("the real number to lager")
print("bingo!")



for 循环:

lucky_num = 50
input_num = 0
for i in range(3):
print("guess count:",i)
input_num = input("input your guess lucky_num:")
if input_num > lucky_num:
print("the real number to smaller")
elif input_num < lucky_num:
print("the real number to lager")
else:
print("bingo!")
break
else:
print("to many retries")

while 循环:
lucky_num = 50
input_num = 0
guess_count = 0
# while lucky_num != input_num and guess_count < 3:
while guess_count < 3:
print("guess count:",guess_count)
input_num = input("input your guess lucky_num:")
if input_num > lucky_num:
print("the real number to smaller")
elif input_num < lucky_num:
print("the real number to lager")
#guess_count = guess_count + 1
else:
print("bingo!")
break
guess_count += 1
else:
print("to many retries")
# if input_num == lucky_num:
# print("bingo!")
# else:
# print("retry to many")


字符串格式:

msg =‘‘‘
information of %s:
Name:%s
Age:%d
Job:%s
‘‘‘%(name,name,age,job)
print(msg)


python-day1

标签:ber   range   ==   little   break   try   字符串   real   raw   

原文地址:http://www.cnblogs.com/oyybin/p/7678085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!