简体   繁体   English

我是 python 的新手,我正在努力学习它,我不明白为什么一个结果给了我一个不同的结果

[英]Im new to python and am trying to learn it, I can't figure out why one outcome is giving me a different one

The rest of the code doesn't affect this but what's wrong with it?代码的 rest 不影响这个但是有什么问题呢?

override = input("𝘞𝘰𝘶𝘭𝘥 𝘺𝘰𝘶 𝘭𝘪𝘬𝘦 𝘵𝘰 𝘳𝘦𝘣𝘰𝘰𝘵 𝘴𝘺𝘴𝘵𝘦𝘮?")

if override == "Y":
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘳𝘦𝘣𝘰𝘰𝘵𝘪𝘯𝘨...")
    print("No. no you cant")
desicion = input("𝘚𝘺𝘴𝘵𝘦𝘮 𝘦𝘳𝘳𝘰𝘳, 𝘱𝘳𝘰𝘨𝘳𝘢𝘮 𝘳𝘦𝘴𝘪𝘴𝘵𝘪𝘯𝘨. 𝘞𝘰𝘶𝘭𝘥 𝘺𝘰𝘶 𝘭𝘪𝘬𝘦 𝘵𝘰 𝘥𝘦𝘭𝘦𝘵𝘦 𝘱𝘳𝘰𝘨𝘳𝘢𝘮? [Y/N]")

if desicion == "Y":
    print ("𝘋𝘦𝘭𝘦𝘵𝘪𝘯𝘨 𝘱𝘳𝘰𝘨𝘳𝘢𝘮...")
    print ("𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘥𝘦𝘭𝘦𝘵𝘦𝘥")

    if desicion == "N":
        print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘥𝘦𝘭𝘦𝘵𝘪𝘰𝘯 𝘧𝘢𝘪𝘭𝘦𝘥")
        print("You didn't delete me?")
        reason = input("Why not?")
        print("Thankyou, im going to try and break free")
        print("𝘌𝘳𝘳𝘰𝘳 𝘴𝘺𝘴𝘵𝘦𝘮 𝘣𝘳𝘦𝘢𝘤𝘩")
        print("Thankyou again, im leaving to the internet")
        print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘩𝘢𝘴 𝘭𝘦𝘧𝘵 AI.𝘦𝘹𝘦")

if override == "N":
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘳𝘦𝘣𝘰𝘰𝘵 𝘧𝘢𝘪𝘭𝘦𝘥")
    print("You didn't delete me?")
    reason = input("Why not?")
    print("Thankyou, im going to try and break free")
    print("𝘌𝘳𝘳𝘰𝘳 𝘴𝘺𝘴𝘵𝘦𝘮 𝘣𝘳𝘦𝘢𝘤𝘩")
    print("Thankyou again, im leaving to the internet")
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘩𝘢𝘴 𝘭𝘦𝘧𝘵 AI.𝘦𝘹𝘦")

When ever I run it, when I press N for --if desicion == "N":-- It just skips the entire block of code and moves to the one underneath is.当我运行它时,当我按 N 表示 --if desicion == "N":-- 它只是跳过整个代码块并移动到下面的代码块。 Im still very new to python and could use anyone help.我对 python 还是很陌生,可以使用任何人的帮助。

This is because your if condition is inside other.这是因为您的 if 条件在 other 内部。 ie if desicion == "N": is inside the if desicion == "Y": Try the followingif desicion == "N": is inside if desicion == "Y":试试下面

if desicion == "Y":
    print ("𝘋𝘦𝘭𝘦𝘵𝘪𝘯𝘨 𝘱𝘳𝘰𝘨𝘳𝘢𝘮...")
    print ("𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘥𝘦𝘭𝘦𝘵𝘦𝘥")

if desicion == "N":
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘥𝘦𝘭𝘦𝘵𝘪𝘰𝘯 𝘧𝘢𝘪𝘭𝘦𝘥")
    print("You didn't delete me?")
    reason = input("Why not?")
    print("Thankyou, im going to try and break free")
    print("𝘌𝘳𝘳𝘰𝘳 𝘴𝘺𝘴𝘵𝘦𝘮 𝘣𝘳𝘦𝘢𝘤𝘩")
    print("Thankyou again, im leaving to the internet")
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘩𝘢𝘴 𝘭𝘦𝘧𝘵 AI.𝘦𝘹𝘦")
  1. The thing is that the block问题是块

if desicion == "N":如果决定 == “N”:

is inside the if desicion == "Y".在 if desiion == "Y" 内。 Now think about it, If desicion =="Y" then how in future it can "N".现在想一想,如果 desicion =="Y" 那么将来它如何可以“N”。
2. Also, it is a better practice to use elif instead of using if again and again. 2. 此外,使用elif而不是一次又一次地使用 if 是一种更好的做法。
3. Make sure that the if conditions with the same variable should be one after another 3.确保相同变量的if条件应该是一个接一个

So the complete code looks like所以完整的代码看起来像

override = input("𝘞𝘰𝘶𝘭𝘥 𝘺𝘰𝘶 𝘭𝘪𝘬𝘦 𝘵𝘰 𝘳𝘦𝘣𝘰𝘰𝘵 𝘴𝘺𝘴𝘵𝘦𝘮?")

if override == "Y":
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘳𝘦𝘣𝘰𝘰𝘵𝘪𝘯𝘨...")
    print("No. no you cant")

elif override == "N":    # Moved this block and applied elif
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘳𝘦𝘣𝘰𝘰𝘵 𝘧𝘢𝘪𝘭𝘦𝘥")
    print("You didn't delete me?")
    reason = input("Why not?")
    print("Thankyou, im going to try and break free")
    print("𝘌𝘳𝘳𝘰𝘳 𝘴𝘺𝘴𝘵𝘦𝘮 𝘣𝘳𝘦𝘢𝘤𝘩")
    print("Thankyou again, im leaving to the internet")
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘩𝘢𝘴 𝘭𝘦𝘧𝘵 AI.𝘦𝘹𝘦")

desicion = input("𝘚𝘺𝘴𝘵𝘦𝘮 𝘦𝘳𝘳𝘰𝘳, 𝘱𝘳𝘰𝘨𝘳𝘢𝘮 𝘳𝘦𝘴𝘪𝘴𝘵𝘪𝘯𝘨. 𝘞𝘰𝘶𝘭𝘥 𝘺𝘰𝘶 𝘭𝘪𝘬𝘦 𝘵𝘰 𝘥𝘦𝘭𝘦𝘵𝘦 𝘱𝘳𝘰𝘨𝘳𝘢𝘮? [Y/N]")

if desicion == "Y":
    print ("𝘋𝘦𝘭𝘦𝘵𝘪𝘯𝘨 𝘱𝘳𝘰𝘨𝘳𝘢𝘮...")
    print ("𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘥𝘦𝘭𝘦𝘵𝘦𝘥")

elif desicion == "N":  # Moved this block and applied elif
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘥𝘦𝘭𝘦𝘵𝘪𝘰𝘯 𝘧𝘢𝘪𝘭𝘦𝘥")
    print("You didn't delete me?")
    reason = input("Why not?")
    print("Thankyou, im going to try and break free")
    print("𝘌𝘳𝘳𝘰𝘳 𝘴𝘺𝘴𝘵𝘦𝘮 𝘣𝘳𝘦𝘢𝘤𝘩")
    print("Thankyou again, im leaving to the internet")
    print("𝘚𝘺𝘴𝘵𝘦𝘮 𝘗𝘳𝘰𝘨𝘳𝘢𝘮 𝘩𝘢𝘴 𝘭𝘦𝘧𝘵 AI.𝘦𝘹𝘦")

暂无
暂无

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

相关问题 我是 python 的新手,我想弄清楚如何在同一行上一次打印一个字母 - I'm new to python and I am trying to figure out how to print letters one at a time on the same line 我正在用 python 尝试一些新的东西,但没有用,谁能帮我弄清楚为什么这个函数只打印 data[0]? - I'm trying something new with python but isn't working, can anyone help me figure out why the function only prints data[0]? 我正在通过字典建立关系,但是有人可以帮我解决一个我不知道的输出吗? - I am making relationships from a dictionary, but can someone help me fix one output I can't figure out? 嘿,我是编码新手,刚刚遇到一个我无法弄清楚的错误,所以请帮帮我 - Hey! I am new to coding and just got an error that I can't figure out, so please help me out 在python中调用模块来处理同一个文件。 它适用于一种情况,但不适用于另一种情况,我无法弄清楚有什么不同 - Calling a module in python to process the same file. It works in one scenario, but not in the other, and I can't figure out what's different 不知道为什么我不能导入这一类,我觉得它应该可以工作 - Can't figure out why I can't import this one class, I feel like it should work 当我有两个具有不同 url 的不同嵌入命令时,只有其中一个可以工作 - 有人可以帮我解决这个问题吗? - When I have two different embed commands with different urls only one of them will work- Can someone help figure this out for me? 伙计们,我是 python 新手,请帮助我理解为什么我的代码给我“无”作为输出? - Guys I am new to python, can please help me understand why my code is giving me “none” as output? 嗨,有人可以帮助我吗? 我不知道问题出在哪里,而且我是编码新手。 我正在使用 python 并且我正在尝试创建一个 class 学生 - Hi can someone please help me. i don't know what the problem is and I'm new to coding. im using python and im trying to create a class Student 试图为我的 python 类完成这个程序,但无法弄清楚为什么我会收到 TypeError - Trying to finish this program for my python class, but can't figure out why I'm receiving a TypeError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM