我的输入,如果不起作用,该如何解决我的代码? Python 2.7.16

问题描述 投票:0回答:1

我的if语句不起作用:

choice = float(input("Enter 1 to enter sec. Enter 2 to enter mins"))
#My problem:
if 'choice' == 1
    a = float(input("Enter secs"))

等...

顺便说一句,我正在做一个计时器,但我需要知道...它告诉我语法无效...

python-2.7
1个回答
0
投票

固定代码(带有我的评论):

choice = int(input("Enter 1 to enter sec. Enter 2 to enter mins")) # no need to use float here
if choice == 1:  # you tried to compare `choice` string with 1 (always False), compare choice variable value with 1 instead. Also note, that you missed : after if
    a = float(input("Enter secs"))
© www.soinside.com 2019 - 2024. All rights reserved.