Python 练习实例48
Python 100例
题目: 数字比较。
程序分析: 无
程序源代码:
实例
#!/usr/bin/python
# -*- coding: UTF-8 -*-
if __name__ == '__main__' :
i = 10
j = 20
if i > j:
print ( '%d 大于 %d' % ( i, j) )
elif i == j:
print ( '%d 等于 %d' % ( i, j) )
elif i < j:
print ( '%d 小于 %d' % ( i, j) )
else :
print ( '未知' )
以上实例输出结果为:
10 小于 20
Python 100例
');
var statusdiv=$('#comment-status');
commentform.submit(function(e){
e.preventDefault();
var noteContent = editor.getValue();
// console.log(noteContent);
noteContent = noteContent.replace(/
/g,"");
noteContent = noteContent.replace(/<\/code><\/pre>/g," ");
// 系列化表单数据
var comment_parent = 0;
var is_user_logged_in = $("#is_user_logged_in").val();
var comment_post_ID = 14225;
var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
var comment = noteContent;
var author = $("#author").val();
var url = $("#url").val();
var email = $("#email").val();
if(isBlank(author) && is_user_logged_in==0) {
statusdiv.html('请输入昵称!
').show();
} else if(isBlank(email) && is_user_logged_in==0) {
statusdiv.html('请输入邮箱!
').show();
} else {
// var formdata=commentform.serialize() + "&comment=" + noteContent ;
// 添加状态信息
statusdiv.html('Processing...
').show();
// 获取表单提交地址
var formurl=commentform.attr('action');
// 异步提交
$.ajax({
type: 'post',
url: formurl,
dataType:'json',
data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
error: function(XMLHttpRequest, textStatus, errorThrown){
statusdiv.html('数据不完整或表单提交太快了!
').show();
},
success: function(data, textStatus){
if(data.errorno=="0") {
$("#submit").prop('disabled', true);
statusdiv.html('笔记已提交审核,感谢分享笔记!
').show();
alert('笔记已提交审核,感谢分享笔记!');
}else{
statusdiv.html(''+data.msg+'
').show();
}
commentform.find('textarea[name=comment]').val('');
}
});
setTimeout(function(){
$("#submit").prop('disabled', false);
}, 10*1000);
}
return false;
});
$(".comt-author").click(function() {
href = $(this).children("a").attr("href");
if(href.indexOf("/note/")!=-1) {
var win = window.open(href, '_blank');
win.focus();
}
});
$(".comt-meta span").hover(function(){
$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
},function(){
$(this).children(".tooltip").removeAttr("style");
});
/*
$(".wrapper i").hover(function(){
$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
},function(){
$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
});
*/
//Upvote.create('runoobvote-id', {callback: vote_callback});
var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
var callback = function(data) {
//console.log($('#runoobvote-id').upvote('upvoted'));
//console.log($('#runoobvote-id').upvote('downvoted'));
//console.log(data);
_vote_action = data.action;
id_arr = data.id.split('-');
um_id= id_arr[2];
//console.log(um_id);
var re = /^[1-9]+/;
if (re.test(um_id)) {
var ajax_data = {
_vote_action: _vote_action,
action: "pinglun_zan",
um_id: um_id,
um_action: "ding"
};
//console.log(ajax_data);
$.post(ajaxurl,ajax_data,function(status){
//if(status.vote_num>999) {
// _voteHtml = ''+kFormatter(status.vote_num) +' ';
// $("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
//}
});
}
};
if($('#comments').length && $('.upvotejs').length){
$('.upvotejs').upvote({id: 14225, callback: callback});
$.post(ajaxurl,{"action":"pinglun_zan","postid":14225},function(data){
$(data).each(function(key,value) {
$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
})
},'json');
}
});
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
// return num;
return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}
Alen
554***[email protected]
封装一个数字比较函数,并比较输入数字:
#!/usr/bin/env python # -*- coding:utf-8 -*- def compare(num1, num2): if num1 > num2: print("%s大于%s" % (num1, num2)) elif num2 > num1: print("%s大于%s" % (num2, num1)) else: print("%s等于%s" % (num1, num2)) if __name__ == "__main__": numOne = input("请输入第一个数字:") numTwo = input("请输入第二个数字:") compare(numOne, numTwo)Alen
554***[email protected]
Webben
wei***[email protected]
运用减法,比较数字大小:
#!/usr/bin/python3 i = 10; j = 20; d = i-j; if d > 0: print('%d 大于 %d ' % (i,j)); elif d == 0: print('%d 等于 %d ' % (i,j)); elif d < 0 : print('%d 小于 %d' % (i,j));Webben
wei***[email protected]
冰封心动
107***[email protected]
Python2.x 与 Python3.x 均可用:
#!/usr/bin/env python # -*- coding:utf-8 -*- def compare(a,b): maxSum = max(a,b) minSum = min(a,b) print('%s比%s大'%(maxSum,minSum)) a = 10 b = 20 compare(a,b)冰封心动
107***[email protected]