[英]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 following即if 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.𝘦𝘹𝘦")
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.