您的位置:首页 > 编程语言 > Python开发

Python学习第四天

2016-01-18 00:00 696 查看
摘要: http://www.runoob.com/python/python-for-loop.html
#!/usr/bin/python

# filename:test4.py

count = 0

while (count < 9):

print ('the count is:',count)

count =count + 1

print ("Good bye!")

i = 1

while i < 10 :

i += 1

if i%2 >0 :

continue

print (i)

# while ....else : else will execute after while finish

count = 0

while count < 5:

print (count,"is less than 5")

count = count + 1

else:

print (count," is not less than 5")

flag = 1

# this sentence is an example of infine loop

#while (flag):print ("Give flag is really true!")

# part two

for letter in 'Python' :

print ('the current character :',letter)

fruits = ['banana','apple','mango']

for fruit in fruits:

print ('current character:',fruit)

print ('Good bye!')

for index in range(len(fruits)):

print ('current fruit:',fruits[index])

print ('Good bye!')

for num in range(10,20):

for i in range(2,num):

if num%i == 0:

j=num/i

print ('%d equals %d * %d' % (num,i,j))

break

else:

print (num,'is a odd prime')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: