lundi 25 janvier 2021

My if statements are being skipped as if they aren`t there and going to the line below the if statement and running that line of code python [duplicate]

So I wouldn`t say im new to python but to the library socket im sort of new. Im trying to make a code like hangouts in python for school and im running into the problem where my If/Else statements are being skipped like this ie:{

    import 'stuff'
    if var == 'str':
        do stuff
    print("Finnished")

} That code is sometime the same as this code ie:{

     import 'stuff'
     do stuff
     print("Finnished")

} my code is Code:{

    from http.server import BaseHTTPRequestHandler, HTTPServer
    import time
    import socket

    hostName = ""
    serverPort = 8080
    MommyIp = "Private info"
    MyIp = "Private info"
    ok = ":"
    Name = input("What do you want your name to be?:    ")
    Namee = Name.encode()
    print("If you want to talk to mom Type 'Yes' if not type 'No'.")



    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    class MyServer(BaseHTTPRequestHandler):
        def do_GET(self):
            self.send_response(200)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write(bytes("<html><head><title>Hangout of the past</title></head>", "utf-8"))
            self.wfile.write(bytes("<body>", "utf-8"))
            self.wfile.write(bytes("<p></p>", "utf-8"))
            self.wfile.write(bytes("</body></html>", "utf-8"))
            while True:
                E = input()
                EE = E.encode()   #bytes
                self.wfile.write(bytes(Namee))
                self.wfile.write(bytes(ok))
                self.wfile.write(bytes(EE))
                self.wfile.write(bytes("<p></p>", "utf8"))
                #s.sendto(EE, serveradress)
                #dataFromServer = clientSocket.recv(1024)
               # #self.wfile.write(bytes(dataFromServer))
                



    if __name__ == "__main__":        
        webServer = HTTPServer((hostName, serverPort), MyServer)
        wdywttt = input("")
        if wdywttt == 'Yes' or 'YEs' or 'YES' or 'yES' or 'yes':
            hostName = MommyIp
            wdywttt = 'null'
            print("Server started http://%s:%s" % (hostName, serverPort))
        
        if wdywttt == 'no' or 'No' or 'NO' or 'nO':
            hostName = MyIp
            wdywttt = 'null'
            print("Server started http://%s:%s" % (hostName, serverPort))
        
        print("Server started http://%s:%s" % (hostName, serverPort))

        try:
            webServer.serve_forever()
        except KeyboardInterrupt:
            pass 

        webServer.server_close()
        print("Server stopped.")

my if statements here

        wdywttt = input("")
        if wdywttt == 'Yes' or 'YEs' or 'YES' or 'yES' or 'yes':
            hostName = MommyIp
            wdywttt = 'null'
            print("Server started http://%s:%s" % (hostName, serverPort))
        
        if wdywttt == 'no' or 'No' or 'NO' or 'nO':
            hostName = MyIp
            wdywttt = 'null'
            print("Server started http://%s:%s" % (hostName, serverPort))

arent working there being skipped. My web server btw was a localhost but now is this:

    ipv4 address:8080

and im storing this code in my G:\ drive and I have a folder called, Family Codes and my code is in that folder. my python is stored in my C:\ drive..

pls help my code. SOO many of my codes have been aborted becuase of this error so pls help my code.. ok bye.

Aucun commentaire:

Enregistrer un commentaire