选择控制循环
原创
©著作权归作者所有:来自51CTO博客作者xiangjie256的原创作品,请联系作者获取转载授权,否则将追究法律责任
def fun(num):
num = num*100;
print '%d' % int(num);
while(num>0):
if(num>=25):
print '%d (25)' % int(num/25);
num = num%25;
elif(num>=10):
print '%d (10)' % int(num/10);
num = num%10;
elif(num>=5):
print '%d (5)' % int(num/5);
num = num%5;
elif(num>=1):
print '%d (1)' % int(num/1);
num = num%1;
fun(0.76)
76
3 (25)
1 (1)
def fun(str):
str.split(str[1]);
if(str[1]=='+'):
print int(str[0])+int(str[2]);
elif(str[1]=='-'):
print int(str[0])-int(str[2]);
elif(str[1]=='*'):
print int(str[0])*int(str[2]);
elif(str[1]=='/'):
print int(str[0])/int(str[2]);
fun('1+2');
fun('1-2');
fun('1*2');
fun('1/2');
3
-1
2
0
def fun():
for i in range(0,20):
if(i%2==0):
print i,;
print;
def fun2(a,b):
if(a%b==0):
print 'true';
else:
print 'false';
fun();
fun2(2,3);
0 2 4 6 8 10 12 14 16 18
false