python高手请进

有几道问题帮帮忙,刚开始学看不太懂什么意思1.Defineaprocedurep2(x)thattakesanintegerparameterx.Ifxisgreater... 有几道问题帮帮忙,刚开始学看不太懂什么意思
1.Define a procedure p2(x) that takes an integer parameter x. If x is greater than 1, the procedure returns the largest power of two that is less than x; otherwise, it returns 0. Use a loop.

2.Define a procedure compare(x,y) that returns 1 if x is greater than y, 0 if x equals y and -1 if x is less than y. Use elif to write the comparison
展开
 我来答
mao_youjia
2008-03-16 · TA获得超过2274个赞
知道小有建树答主
回答量:523
采纳率:50%
帮助的人:488万
展开全部
1\定义一个过程p2(x),它接受一个字符变量X,如果X大于1,则该过程返回一个小于x的最大的2的乘方。否则,返回0。使用循环。

2、定义一个过程compare(x,y),如果x大于y则返回1,如果x等于y返回0,x小于y返回-1。使用elif语句来完成比较。

我顺便帮你把文件写出来好了

# -*- coding: cp936 -*-
i=0

def p2(x):
     if x>i :
         i=i*2
     else :
         return i/2
     p2(x)

def compare(x,y):
     if x>y:
         return 1
     elif x==y :
         return 0
     elif x<y :
         return -1
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式