简体   繁体   English

为什么我的终端不显示任何内容?

[英]Why doesn't show anything in my terminal?

I was trying to make a program to see what is the biggest number that my computer can reach in only 3 seconds.我试图编写一个程序来查看我的计算机在 3 秒内可以达到的最大数字是多少。 But in the terminal doesn't show anything, why?但是在终端什么都没有显示,为什么?

This was my code:这是我的代码:

import time


inicio=0
t=3
i=0

while inicio<=t:
    inicio+=1
    time.sleep(1)
while inicio<=t:
    i+=1
    print(i)    
        

This code works:此代码有效:

import time


inicio=0
t=3
i=0

while inicio <= t:
    inicio += 1
    time.sleep(1)
    i += 1
    print(i)

however it is very slow.但是它很慢。 You need to tweak it a lot to get an accurate number.您需要对其进行大量调整才能获得准确的数字。 The reason your original code did not work was because the first while loop stops the second one from working and the second one is pointless.您的原始代码不起作用的原因是因为第一个 while 循环使第二个循环停止工作,而第二个循环毫无意义。 if the parameters are the same you must use 1 while loop not 2 or the first will cancel out the second.如果参数相同,则必须使用 1 而不是 2 循环,否则第一个将抵消第二个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM