Python,如何制作一个倒计时时钟,询问用户希望从哪个数字开始

Python,如何制作一个倒计时时钟,询问用户希望从哪个数字开始,python,Python,好的,所以我是python新手,我真的需要一些帮助。这是到目前为止我的代码。我一直遇到语法错误,我不知道我做错了什么 count = int(input("What number do you want the timer to start: ")) count == ">" -1: print("count") print("") count = count - 1 time.sleep(1) 在第二行中,不能从“>”中减去1,因为“>”是一个字符串。 这里你需要的显然是一个for循环

好的,所以我是python新手,我真的需要一些帮助。这是到目前为止我的代码。我一直遇到语法错误,我不知道我做错了什么

count = int(input("What number do you want the timer to start: "))
count == ">" -1:
print("count")
print("")
count = count - 1
time.sleep(1)

在第二行中,不能从“>”中减去1,因为“>”是一个字符串。 这里你需要的显然是一个for循环。编辑:你也忘了导入

import time
count = int(input("What number do you want the timer to start: "))
for i in range(count):
    print("count")
    print(i)
    count = count - 1
    time.sleep(1)

在第二行中,不能从“>”中减去1,因为“>”是一个字符串。 这里你需要的显然是一个for循环。编辑:你也忘了导入

import time
count = int(input("What number do you want the timer to start: "))
for i in range(count):
    print("count")
    print(i)
    count = count - 1
    time.sleep(1)

语法错误可能来自以下行

count == ">" -1:
我不知道你从哪里弄来的!您需要的是一个循环,该循环在计数器用完时停止,否则将重复相同的代码

count = int(input("What number do you want the timer to start: "))
while count > 0:
    print("count", count)
    print("")
    count = count - 1
    time.sleep(1)

您也可以将
count=count-1
替换为
count-=1
,但这不会对代码的操作产生任何影响。

语法错误可能来自读取的行

count == ">" -1:
我不知道你从哪里弄来的!您需要的是一个循环,该循环在计数器用完时停止,否则将重复相同的代码

count = int(input("What number do you want the timer to start: "))
while count > 0:
    print("count", count)
    print("")
    count = count - 1
    time.sleep(1)

您也可以将
count=count-1
替换为
count-=1
,但这不会对代码的操作产生任何影响。

在访问time.sleep方法之前,您需要确保导入时间库

此外,使用循环来重复代码可能更有效。if语句的结构也不正确,不是正确的表达式

IF <Expression> is TRUE:
    DO THIS.
解释

for countdown in range(count,0,-1): 

范围(起点、终点、步长)。从给定整数开始,以0结束,每次迭代步数为-1。

在访问time.sleep方法之前,需要确保导入时间库

此外,使用循环来重复代码可能更有效。if语句的结构也不正确,不是正确的表达式

IF <Expression> is TRUE:
    DO THIS.
解释

for countdown in range(count,0,-1): 

范围(起点、终点、步长)。从给定的整数开始,以0结束,每次迭代步数为-1。

首先,必须
导入时间
才能使用
time.sleep()
函数

接下来,我不太清楚你说的是什么意思:

count==“>”-1:

如果您正在创建“秒表”,那么使用某种循环是合乎逻辑的:

while count > 0:
    print(count,"seconds left")
    count -= 1
    time.sleep(1)

print ("Finished")

这应该可以正常工作。

首先,您必须
导入时间
,才能使用
time.sleep()
函数

接下来,我不太清楚你说的是什么意思:

count==“>”-1:

如果您正在创建“秒表”,那么使用某种循环是合乎逻辑的:

while count > 0:
    print(count,"seconds left")
    count -= 1
    time.sleep(1)

print ("Finished")

这应该可以。第二行有语法错误。我不确定你在那里想要实现什么。可能需要检查计数是否大于-1

这样做:

import time
count = int(input("What number do you want the timer to start: "))
if count>0:
  while(count):
    print(count)
    time.sleep(1)
    count = count -1

第二行出现语法错误。我不确定你在那里想要实现什么。可能需要检查计数是否大于-1

这样做:

import time
count = int(input("What number do you want the timer to start: "))
if count>0:
  while(count):
    print(count)
    time.sleep(1)
    count = count -1

如果您有错误,请包含该错误并指定错误发生的行该行应该做什么
count==“>”-1:
?您正在检查从字符串中减除的1的相等性(您不能这样做)。此外,请修复代码的格式。除非您的代码是逐字记录的,否则在这种情况下,错误显然是(或也是)关于缺少缩进的。如果您有错误,请包含错误并指定错误发生的行。这一行到底应该做什么
count==“>”-1:
?您正在检查从字符串中减除的1的相等性(您不能这样做)。此外,请修复代码的格式。除非您的代码是按原样编写的,否则在这种情况下,错误显然(或同时)与缺少缩进有关。