【发布时间】:2022-01-31 06:33:56
【问题描述】:
每次 while 循环继续时,y 的值都会发生变化,我尝试了观察点模块,但我需要一种方法来找出最高的 y 并打印它,我将打印我正在尝试的代码去上班。
import random
from watchpoints import watch
def alg(I):
print(I)
x = 1
while i > 1:
if (i % 2) == 0:
i = int(i / 2)
x = x + 1
else:
i = int(3 * i + 1)
x = x + 1
print(I)
y = 1
if i in range(1, 9):
y = 1
if i in range(10, 99):
y = 2
if i in range(100, 999):
y = 3
if i in range(1000, 9999):
y = 4
watch(a)#I want to know when y reachest the highest
print(y, "is the max number of caracters")#then print it
print("numero passaggi = ", str(x))
print("1: choice")
print("2: random")
type = int(input(" 1 or 2: "))
if type == 1:
i = input("Enter a number: ")
alg(int(I))
elif type == 2:
i = random.randint(1, 100) # 10^9
alg(I)
else:
print("Enter 1 or 2")
我想知道y什么时候达到最高点并在下面打印出来。
【问题讨论】:
-
您可以创建一个变量
max_y,如果新的y大于max_y,则每次更新该变量。您可以从那里跟踪。
标签: python python-3.x algorithm math watch