簡體   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

代碼的 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.𝘦𝘹𝘦")

當我運行它時,當我按 N 表示 --if desicion == "N":-- 它只是跳過整個代碼塊並移動到下面的代碼塊。 我對 python 還是很陌生,可以使用任何人的幫助。

這是因為您的 if 條件在 other 內部。 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.𝘦𝘹𝘦")
  1. 問題是塊

如果決定 == “N”:

在 if desiion == "Y" 內。 現在想一想,如果 desicion =="Y" 那么將來它如何可以“N”。
2. 此外,使用elif而不是一次又一次地使用 if 是一種更好的做法。
3.確保相同變量的if條件應該是一個接一個

所以完整的代碼看起來像

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM