
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 展开
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 展开
1个回答
展开全部
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
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询