Python程序反转给定数字(2种不同方式)

本文介绍了两种在Python中反转用户输入数字的方法:一种是直接在主程序中迭代,另一种是通过用户定义的函数实现。两种方法都通过计算余数和逐次累加来达到反转效果。
摘要由CSDN通过智能技术生成

Take input number from the user and print its reverse.

从用户处获取输入号码并打印其反面。

Example:

例:

    Input:
    12345

    Output:
    54321

Here, we are implementing program to reversing a given number using 2 different ways.

在这里,我们正在实施程序,以使用2种不同的方式来反转给定的数字

1) Famous approach for reversing the number: Take input from the user and typecast into an integer, then iterate in the loop till num is not become zero, inside the loop:

1) 逆转数字的著名方法 :从用户输入并将其类型转换为整数,然后在循环中循环直到num在循环内不为零:

  • Find out the remainder.

    找出其余的。

  • Using this: rev_num = rev_num * 10 + remainder.

    使用这个:rev_num = rev_num * 10 +余数。

  • Update that number by diving by 10.</

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值