运用Pyhon3的整数除法和取余运算,编写程序计算1234s相当于几分几秒?

运用Pyhon3的整数除法和取余运算,编写程序计算1234s相当于几分几秒?,第1张

要计算1234秒相当于几分几秒,可以使用Python3的整数除察闷法和取余运算。整歼竖数除氏没大法可以用//表示,取余运算可以用%表示。

## 代码实现

下面是Python3代码实现:

total_seconds = 1234

minutes = total_seconds // 60

seconds = total_seconds % 60

print("1234秒相当于{}分{}秒".format(minutes, seconds))

## 运行结果

运行上面的代码,输出结果为:

1234秒相当于20分34秒

因此,1234秒相当于20分34秒。

这个是 python2.7 的代码,如果是 python3.x 的话,改一下 print 函数就好。

if __name__ == '__main__':

    list_three = []

    list_six = []

    list_nine = []

    for i in range(1, 301):

        if i % 3 贺芹则== 0 or str(i).find('3') <> -1:

            list_three.append(i)

        if i % 6 == 0 or str(i).find('6') <> -1:

            list_six.append(i)

        if i % 9 == 0 or str(i).find('9') <> -1:

  首迟          list_nine.append(i)

    print '3 output: '

    for item in list_three:

        print item, 

    print ''

    print '6 output: '

    for item in list_six:

        print item, 

    print ''

    print '9 output: '

    for item in list_nine:

        print 禅棚item, 

    print '


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12524874.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存