我最近遇到了一个问题,该代码将在第69行附近重复出现。我不知道为什么会这样,任何帮助都将是惊人的。这是代码。
import time
import threading
import random
totalviews = 0
videoViews = 0
totallikes = 0
videolikes = 0
totaldislikes = 0
videodislikes = 0
subscribers = 0
videolength = 0
midroles = 0
uploadTimer1 = 0
waitTimer1 = 0
x = 0
comadymins = 0
comadysecs = 0
def timer1():
global uploadTimer1
global waitTimer1
global x
time.sleep(.75)
if x == 1:
print(uploadTimer1, 'mins remaining')
uploadTimer1 -= 1
time.sleep(60)
if uploadTimer1 == 0:
x = 0
Timer1 = threading.Thread(target=timer1)
print('')
print("you decided to start a youtube channel")
while True:
time.sleep(1.25)
print('')
print('what type of video will you make')
print('1. comedy')
print('2. gaming')
print('3. science')
print('4. check timer')
UserInput = input('')
if UserInput == '1':
if waitTimer1 == 0:
comadymins = random.randint(10, 30)
comadysecs = random.randint(0, 60)
time.sleep(0.1)
print('video length will be', comadymins, ":", comadysecs)
time.sleep(1)
if comadymins <= 29 and comadysecs <= 59:
print('would you like to upload now?')
time.sleep(.5)
UserInput = input('')
if UserInput == 'y':
print('video is uploading')
print('it will take 4 mins')
uploadTimer1 += 4
x += 1
Timer1.start()
waitTimer1 += 1
else:
print('okay')
if comadymins <= 19 and comadysecs <= 59:
print('would you like to upload now?')
time.sleep(.5)
UserInput = input('')
if UserInput == 'y':
print('video is uploading')
print('it will take 4 mins')
waitTimer1 += 1
uploadTimer1 += 4
x += 1
Timer1.start()
else:
print('okay')
else:
print('you already have a video running')
time.sleep(1)
if UserInput == '4':
print('okay')
print(uploadTimer1, "mins remaining")
任何帮助都将是惊人的。我对编码也很陌生,因此如果代码混乱或不符合平均标准,将感到抱歉。我只编写了大约一个月的代码,如果您有任何令人惊奇的建议,每周大约要进行3个小时。
[状态为while True:
时,您有一个无限循环这将永远贯穿它下面的所有线条。如果满足特定条件,可以通过在循环内添加一个中断来退出此循环。
您的问题是,您拥有相同的打印数据,“您现在要上传吗?”和两个条件语句,它们的行为方式相同。你有一个
if comadymins <= 29 and comadysecs <= 59:
和一个
if comadymins <= 19 and comadysecs <= 59:
因为您在这里有一个随机数:
comadymins = random.randint(10, 30)
类似于“ 11”同时小于“ 19”和“ 29”,因此您的两个条件都将触发,并且您会看到重复的句子“您现在要上传吗?”。您应该按照问题的逻辑进行工作。