调用函数时,“ If”语句将被忽略

Nramosruballos

我正在尝试创建一个简单的程序,该程序将要求用户输入年龄,然后要求用户输入另一个年龄以找出差异。

当我要求用户确认年龄时,程序中的问题就出现了。当我要求用户确认年龄时,如果用户的回答确认了他们的选择,我希望程序继续运行。但是目前,我陷入了一个循环,即使用户输入了确认信息,该程序也会跳过我的if语句并始终运行我的else:语句。

#This program will prompt you to state your age and then will proceed to
#calculate how long till __ age

print("Hello. ")

while True:
    try:
        myAge = int(input("Please enter your age: ")) #int( makes func be a #
    except ValueError:
        print("I'm sorry, please enter your age as a numeric value.")
        continue #Continue function loops back to the function making it 'continue'
    else: #If it is a # then it breaks 
        break

#Going to ask for the second variable
print("You are " + str(myAge) + ".")
print("What is your desired age? ")
 
def secondV():
    desiredAge = int(input())
    print("You wish to be " + str(desiredAge) + "?")
    yourWish = input()
 
desiredAge = int(input())
print("Do you wish to be " + str(desiredAge) + "?")
yourWish = input()
 
def choose():
        if yourWish == "Yes" and yourWish == "yes" and yourWish == "y" and yourWish == "Y":
                    print("Okay... calculating")
                    print("To be " + str(desiredAge) + ", you would have to wait " + str(desiredAge - myAge) + " years. ")
                


else:
        print("Erm... please input your desired age now:")
        secondV()
        if desiredAge == 'yes' and desiredAge == 'Yes':
            print(Yes())
        else:
            No()

choose()
print('Goodbye.')
Pratik Agrawal

出现一些缩进错误,您使用和关键字代替了或关键字,这是一个有效的代码

print("Hello. ")

while True:
    try:
        myAge = int(input("Please enter your age: ")) #int( makes func be a #
    except ValueError:
        print("I'm sorry, please enter your age as a numeric value.")
        continue #Continue function loops back to the function making it 'continue'
    else: #If it is a # then it breaks 
        break


#Going to ask for the second variable


print("You are " + str(myAge) + ".")
 
 
print("What is your desired age? ")
 
def secondV():
    desiredAge = int(input())
    print("You wish to be " + str(desiredAge) + "?")
    yourWish = input()
 
desiredAge = int(input())
print("Do you wish to be " + str(desiredAge) + "?")
yourWish = input()
 
def choose():
    if yourWish == "Yes" or yourWish == "yes" or yourWish == "y" or yourWish == "Y":
        print("Okay... calculating")
        print("To be " + str(desiredAge) + ", you would have to wait " + str(desiredAge - myAge) + " years. ")
                


    else:
        print("Erm... please input your desired age now:")
        secondV()
        if yourWish == 'yes' or yourWish == 'Yes':
            print("Okay... calculating")
            print("To be " + str(desiredAge) + ", you would have to wait " + str(desiredAge - myAge) + " years. ")
        
        else:
            print("Erm... please input your desired age now:")
            secondV()
            choose()

choose()
 
print('Goodbye.')

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Javascript isNaN()函数将被忽略

来自分类Dev

在后台定期调用stopLeScan时将被忽略

来自分类Dev

for循环中的if语句将被忽略

来自分类Dev

for循环中的if语句将被忽略

来自分类Dev

通过 IF 语句调用函数时的问题

来自分类Dev

无默认值的R函数值将被忽略

来自分类Dev

从Nexus下载时,常春藤的transitive =“ false”将被忽略

来自分类Dev

使用--action = runas时,cygstart --directory开关将被忽略

来自分类Dev

保存到文件时,空格后面的单词将被忽略

来自分类Dev

Ajax调用忽略了我的if语句

来自分类Dev

Ajax调用忽略了我的if语句

来自分类Dev

哪些订单函数将被调用

来自分类Dev

AutoMapper:调用Map()函数时忽略一些参数

来自分类Dev

调试时使用函数调用语句作为异常源

来自分类Dev

在“ if”语句中调用std :: set函数时,意外的评估结果

来自分类Dev

调试时使用函数调用语句作为异常源

来自分类Dev

调用MySQL函数时,PHP准备的语句失败

来自分类Dev

调用post方法时,如果密码对应,则输入if语句,但是if语句中的res被忽略,为什么?

来自分类Dev

在PHP三元操作中两次使用某个函数时,该函数将被调用一次?

来自分类Dev

如果语句在主函数中被忽略

来自分类Dev

PL / SQL函数语句忽略错误

来自分类Dev

Java POI导出到具有空行的excel时将被忽略

来自分类Dev

通过iOS Mail查看html电子邮件时,@ media查询将被忽略

来自分类Dev

通过REST API创建订单时,帐户上的PayPal销售税设置将被忽略

来自分类Dev

当使用伪造者“闯入内部:避免”生成PDF时,将被忽略

来自分类Dev

当语法在vue组件中看起来很完美时,“外部根元素将被忽略”错误

来自分类Dev

当我遍历文件时,第二个for循环将被忽略

来自分类Dev

Java POI导出到具有空行的excel时将被忽略

来自分类Dev

循环开始时,其他所有内容都将被忽略

Related 相关文章

  1. 1

    Javascript isNaN()函数将被忽略

  2. 2

    在后台定期调用stopLeScan时将被忽略

  3. 3

    for循环中的if语句将被忽略

  4. 4

    for循环中的if语句将被忽略

  5. 5

    通过 IF 语句调用函数时的问题

  6. 6

    无默认值的R函数值将被忽略

  7. 7

    从Nexus下载时,常春藤的transitive =“ false”将被忽略

  8. 8

    使用--action = runas时,cygstart --directory开关将被忽略

  9. 9

    保存到文件时,空格后面的单词将被忽略

  10. 10

    Ajax调用忽略了我的if语句

  11. 11

    Ajax调用忽略了我的if语句

  12. 12

    哪些订单函数将被调用

  13. 13

    AutoMapper:调用Map()函数时忽略一些参数

  14. 14

    调试时使用函数调用语句作为异常源

  15. 15

    在“ if”语句中调用std :: set函数时,意外的评估结果

  16. 16

    调试时使用函数调用语句作为异常源

  17. 17

    调用MySQL函数时,PHP准备的语句失败

  18. 18

    调用post方法时,如果密码对应,则输入if语句,但是if语句中的res被忽略,为什么?

  19. 19

    在PHP三元操作中两次使用某个函数时,该函数将被调用一次?

  20. 20

    如果语句在主函数中被忽略

  21. 21

    PL / SQL函数语句忽略错误

  22. 22

    Java POI导出到具有空行的excel时将被忽略

  23. 23

    通过iOS Mail查看html电子邮件时,@ media查询将被忽略

  24. 24

    通过REST API创建订单时,帐户上的PayPal销售税设置将被忽略

  25. 25

    当使用伪造者“闯入内部:避免”生成PDF时,将被忽略

  26. 26

    当语法在vue组件中看起来很完美时,“外部根元素将被忽略”错误

  27. 27

    当我遍历文件时,第二个for循环将被忽略

  28. 28

    Java POI导出到具有空行的excel时将被忽略

  29. 29

    循环开始时,其他所有内容都将被忽略

热门标签

归档