python倒数怎么求_python倒数问题

Completethefollowingtwofunctions:#Returnsthereversalofaninteger.#Forexamplereverse(456)returns654defreverse(number):#Returnstrueifnumberisapalindromedefis_palindrome(numb...

Complete the following two functions:

# Returns the reversal of an integer.

# For example reverse(456) returns 654

def reverse(number):

# Returns true if number is a palindrome

def is_palindrome(number):

Use the reverse function to implement the is_palindrome function. A number is a palindrome if its reversal is the same as itself. Write a main function that prompts the user to enter an integer, calls the is_palindrome function (the is_palindrome function will call thereverse function) and then reports whether the integer is a palindrome or not. The template for the question is given below:

# Template starts here

def reverse(number):

# Write code that reverses the number and then returns the reversed number.

def is_palindrome(number):

# Write code that call the reverse function, process the value returned by the reverse function.

# Return True if the number is a palindrome and False otherwise.

def main():

# Write code to prompt the user to enter an integer, calls the is_palindrome function and (depending on the value returned by the is_palindrome function) reports if the number is a palindrome or not.

main() # Call the main function

# Template ends here

Sample Output

Enter a number: 222

The number is a palindrome.

Another Sample Output:

Enter a number: 456

The number is not a palindrome.

必须用上3个def

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值