# coding: utf-8
import time
def collatz():
"""用户输入一个参数,对参数进行整理校对(collatz)
如果是奇数:3*number + 1
如果是偶数 number//2"""
print('Please enter a number:')
number = int(input())
num_number = []
start = time.time()
while True:
if number == 1:
break
elif number % 2 == 0:
number = number // 2
num_number.append(number)
continue
elif number % 2 != 0:
number = 3 * number + 1
num_number.append(number)
continue
end = time.time()
print('循环时间:', (end - start))
print(num_number)
return number
collatz()
《python编程上手让繁琐的工作自动化》——collat函数以及time用法
最新推荐文章于 2023-11-24 17:34:59 发布