Python if/else命令不起作用?

Python if/else命令不起作用?,python,function,python-3.x,if-statement,Python,Function,Python 3.x,If Statement,我一直在编写一个基于文本的黑客小游戏,下面是我的代码 #SICCr4k2: Broke # # # #Remember whenever you are printing a random ip address to add the "." in between each part of the ip (each random number) ## LAST LEFT ON HERE: MAKE BUTTONS FOR NODES ## MAKE FILES FOR NULL'S NODE #

我一直在编写一个基于文本的黑客小游戏,下面是我的代码

#SICCr4k2: Broke
#
#
#
#Remember whenever you are printing a random ip address to add the "." in between each part of the ip (each random number)

## LAST LEFT ON HERE: MAKE BUTTONS FOR NODES
## MAKE FILES FOR NULL'S NODE
## SET THE CORRECT PLACEMENTS FOR ALL THE BUTTONS
## nullMain referenced before assignment
## make it so that you send a message through the prompt to get their ip, then it automatically puts the ip in the nodes
## window. Like you send the person a message, and then it gets the ip and puts it in the nodes window
## take away the buttons in the nodes window, just at labels where it points to the host's ip address.
## Don't use tkinter buttons anymore
## Regular Campaign, separate program for free roam hacking
## At the end, make it so Null betrayed you and you have to destroy his computer, destroy him.


import random
import time
import sys
import os
import tkinter as tk
from tkinter import *

#def nodes():
#   nodeWindow = tk.Tk()
#   frame = tk.Frame(nodeWindow, width=700, height=400)
#   frame.grid_propagate(0)
#   frame.grid()
#   nodeWindow.title("||| Nodes |||")
#   nodeWindow.iconbitmap(r'C:\Users\John\Desktop\Programming\SICCr4k2BrokeFold\BrokeItems\NodeIcon.ico')
#   nodeWindow.wm_resizable(0,0);
#   nullMain = tk.Button(nodeWindow, text="Null", function=nullMainCallback())
#   nullMain.config(height=1, width=100)
#   nullMain.grid(row=0, column=0)
#   def nullIpBackCallBack():
#       nullMain = tk.Button(nodeWindow, text="Null", function=nullMainCallback())
#       nullMain.config(height=1, width=100)
#       nullMain.grid(row=0, column=0)
#   def nullMainCallback():
#       nullMain.destroy()
#       nullIp = tk.Label(nodeWindow, text="Ip: 221.153.52.216")
#       nullIp.grid(row=0, column=0)
#       nullIpBack = tk.Button(nodeWindow, text="Back", function=nullIpBackCallBack())
#       nullIpBack.grid(row=1, column=0)

sys.setrecursionlimit(99999)

def nodes1():
    nullIp = ('18.226.109')
    print('||| Nodes ||||')
    print(' ')
    print('Null')
    print('')
    nodeInput1 = input('>>> ')
    if nodeInput1 == ('null') or ('Null'):
        print("Null's ip: " + nullIp + "                 <<<back")

def connecting():
    #TRY TO MAKE 'CONNECTING' CENTERED
    time.sleep(1)
    print('Connecting')
    time.sleep(1)
    os.system('cls')
    print('Connecting.')
    time.sleep(1)
    os.system('cls')
    print('Connecting..')
    time.sleep(1)
    os.system('cls')
    print('Connecting...')
    time.sleep(1)
    os.system('cls')
    print('Connecting')
    time.sleep(1)
    os.system('cls')
    print('Connecting.')
    time.sleep(1)
    os.system('cls')
    print('Connecting..')
    time.sleep(1)
    os.system('cls')
    print('Connecting...')
    time.sleep(1)
    os.system('cls')
    print('Connecting')
    time.sleep(1)
    os.system('cls')
    print('Connecting.')
    time.sleep(1)
    os.system('cls')
    print('Connecting..')
    time.sleep(1)
    os.system('cls')
    print('Connecting...')
    time.sleep(1)
    os.system('cls')
    print('You are now connected.')

def connectNull_Tutorial():
    #MAKE EVERYTHING CENTERED WELL
    numbers()
    time.sleep(2)
    os.system('cls')
    connecting()
    print('You now have access to (comp ID): Null')
    time.sleep(2)
    os.system('cls')
    print('Type what you want access to:')
    print('Files | Options | Mainframe')
    time.sleep(2)
    def nullFiles_Tutorial():
        print('Go ahead and type Files.')
        input('>>> ')
        if ('files') or ('Files'):
            print('Files:')
            print('Key: (T)Text file | (E)Executable | (F)Folder')
            print('')
            print('')
            print('')
            print("""screenNames.T""")
            time.sleep(2)
            def screenNames_Tutorial():
                print('Now type in screenNames.T, exactly as it is.')
                input('>>> ')
                if ('screenNames.T'):
                    print('|screenNames.T|')
                    print('')
                    print('ras1aB, p0Nk, killT0n, raspberryH4cker, 314dk0m')
                    print('h4ckB3rr13s, b3y0ndPyth0n, j03Dr4n, jitsl3d, 01f0r4')
                    time.sleep(2)
                    print('These names...')
                    time.sleep(2)
                    print('These people, they need to be dealt with.')
                    time.sleep(2)
                    print("It's time to start making this world a better place.")
                    print("Remember getIp()? Put it to good use with these names")

                else:
                    screenNames_Tutorial()
            screenNames_Tutorial()
        else:
            nullFiles_Tutorial()
    nullFiles_Tutorial()

def numbers():
    def numbersCode():
        t_end = time.time() + 5
        while time.time() < t_end:
            number1 = random.randint(100, 999)
            number2 = random.randint(100, 999)
            number3 = random.randint(100, 999)
            number4 = random.randint(100, 999)
            print(str(number1) + ' ' + str(number2) + ' ' + str(number3) + ' ' + str(number4) + ' ' + str(number1) + ' ' + str(number2) + ' ' + str(number3) + ' ' + str(number4) + ' ' + str(number1) + ' ' + str(number2) + ' ' + str(number3) + ' ' + str(number4) + ' ' + str(number1) + ' ' + str(number2) + ' ' + str(number3) + ' ' + str(number4))
    numbersCode()

#def getIp():
#   x = random.randint(1, 222)
#   if x == 127:
#       x += 1
#   return '{}.{}.{}.{}'.format(
#       x,
#   random.randint(0, 255),
#   random.randint(0, 255),
#   random.randint(0, 255))

def usernameCreation():
    username = input(">>> ")
    print("'" + username + "' is that correct?")
    usernameInput = input(">>> ")
    if usernameInput == ("yes"):
        print("Okay...")
    if usernameInput ==("no"):
        usernameCreation()

def game():
    def tutorial():
        print('Hello.')
        time.sleep(3)
        print('Welcome back.')
        time.sleep(3)
        print("You're probably wondering who I am.")
        time.sleep(3)
        print("You might also be wondering what the hell is happening")
        time.sleep(5)
        print('Well, my name is Null')
        time.sleep(3)
        print("And I'm dead.")
        time.sleep(5)
        print("I've downloaded new software onto your computer.")
        os.system('cls')
        print("First thing's first, what shall I call you?")
        usernameCreation()
        time.sleep(3)
        def firstMove():
            print("""Let's give you some movement. What you're going to have to do 
is type, getIp(Null), in other cases you will have to replace Null with
the person's screen name. It IS case sensitive""")
        firstMove()
        def repeatCommand1():
            print('Go right ahead, getIp(Null)')
            commandInput = input(">>> ")
            if ('getIp(Null)'):
                numbers()
                time.sleep(3)
                print('Ip address added to your nodes.')
                time.sleep(2)
                os.system('cls')
                print("""Now you will need to type myNodes(), which will give you access to all the
ip addresses you have found out so far. Then you will need to type in the
screen name of the person you need the ip of.""")
                def myNodes1():
                    print("So go ahead. myNodes()")
                    input(">>> ")
                    if ('myNodes()'):
                        nodes1()
                        print("""I just downloaded a bypasser and a password decrypter to your computer. I want you to try
    to hack into my computer. First use, connectIp(18.226.109)""")
                        input(">>> ")
                        if ('connectIp(18.226.109)'):
                            connectNull_Tutorial()

                    else:
                        print('That is an incorrect command.')
                        myNodes1()
                myNodes1()
            else:
                repeatCommand1()

        repeatCommand1()
    tutorial()
game()
然后:

我会尽力澄清的。上面写着:

        def repeatCommand1():
            print('Go right ahead, getIp(Null)')
            commandInput = input(">>> ")
            if ('getIp(Null)'):
                numbers()
                time.sleep(3)
                print('Ip address added to your nodes.')
                time.sleep(2)
                os.system('cls')
                print("""Now you will need to type myNodes(), which will give you access to all the
ip addresses you have found out so far. Then you will need to type in the
screen name of the person you need the ip of.""")
                def myNodes1():
                    print("So go ahead. myNodes()")
                    input(">>> ")
                    if ('myNodes()'):
                        nodes1()
                        print("""I just downloaded a bypasser and a password decrypter to your computer. I want you to try
    to hack into my computer. First use, connectIp(18.226.109)""")
                        input(">>> ")
                        if ('connectIp(18.226.109)'):
                            connectNull_Tutorial()

                    else:
                        print('That is an incorrect command.')
                        myNodes1()
                myNodes1()
            else:
                repeatCommand1()
它清楚地,或者说有点清楚地表明,如果你输入了废话,那么就这样做,如果你输入了其他任何东西,就从头开始,反复输入,直到你输入了正确的东西。例如:

def goBack():
    print('Enter getIp(Null)')
    input()
    if ('getIp(Null)'):
        print('Good job mate')
    else:
        goBack()
goBack()
(请注意,上面的代码是用作示例的,不一定是我在实际程序中的代码)。该程序似乎接受了我输入的任何输入,并且仍然(使用上面的示例)打印“GoodJobMate”,即使我没有输入getIp(Null)。在我的代码中,每一个出现类似上面代码的地方,都会弹出相同的错误。我可以直接运行程序,只需按enter键就可以玩整个(当前)游戏。有人知道该怎么做吗

result = input(">>>")
if result == "Something":
   do_something()

这是非常基本的。。。你应该更经常地运行你的代码…

你应该阅读并编辑你的问题,这不是
input()
的工作原理。如果
也能工作,那就不是
的工作原理了…@IgnacioVazquez Abrams我想,既然我在一个测试程序中试用过,我就可以这样做。如果a==('hello'):print('gj mate')
if('getIp(Null)
is
true
是因为非空字符串是
true
,那么我应该为输入分配一个变量,比如a=input()。我认为您必须删除
'getIp(Null)
中的引号,并取消对
getIp
函数的注释。很抱歉,我真的应该这样做。感谢您帮助我认识到我的错误,我可能应该坚持我学习python的方式,停止尝试走捷径,当然,只停止那些不起作用的捷径。
def goBack():
    print('Enter getIp(Null)')
    input()
    if ('getIp(Null)'):
        print('Good job mate')
    else:
        goBack()
goBack()
result = input(">>>")
if result == "Something":
   do_something()