John Antonio Anselmo John Antonio Anselmo - 6 months ago 11
Python Question

Python if/else command not working?

I've been programming a little text based hacking game, my code will be below.

#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()


The problem with the program, is that where there is an if/else command, it doesn't work. I tested out the program just now, to see that when I enter in any sort of input (wherever in the code it says
input('>>> ')
and then:

if ('blah'):
print('blah')


then:

else:
commandThatgoesBack


I'll try clarifying. Where it says:

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()


It clearly, or somewhat clearly states that if you input blah, do this, if you enter anything else, start from the beginning, and input again, over and over until you input the correct thing. Such as:

def goBack():
print('Enter getIp(Null)')
input()
if ('getIp(Null)'):
print('Good job mate')
else:
goBack()
goBack()


(Do note that the code above is used as an example and not necessarily exactly how my code in the actual program is). The program seems to take any input that I enter, and still (using the example above) prints 'Good job mate', even if I don't enter getIp(Null). Every single place in my code where something like the code above appears, the same error pops up. I can literally run the program, and play the whole (current) game just by pressing enter. Anyone know what to do?

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

this is pretty basic ... you should probably be running your code more often ...