我的程序没有';不会有任何语法错误,只是不会做它的本意(Python)

我的程序没有';不会有任何语法错误,只是不会做它的本意(Python),python,Python,我想让它找出为什么在再次输入密码时不运行其余的代码,即使它仍然正确地说拒绝访问,并执行其他命令的过程。您有下面一行生成一个int import random import time print ("Welcome to 'Project X'") print ("----------------------") login = input("Please enter your username:") time.sleep(1) prin

我想让它找出为什么在再次输入密码时不运行其余的代码,即使它仍然正确地说拒绝访问,并执行其他命令的过程。

您有下面一行生成一个
int

import random
import time
print ("Welcome to 'Project X'")
print ("----------------------")
login = input("Please enter your username:")
time.sleep(1)
print ("Please wait...")
time.sleep(1)
print ("Generating randomized password")
password = random.randint(1000000000, 9000000000)
time.sleep(3)
print ("This is your randomized password:", password)
print ("Write down your password, you have 10 seconds")
time.sleep(10)
import os
os.system("cls")
login2 = input("Please enter your username:")
if login2 == login:
    password2 = input("Please enter your password:")
    if password2 == password:
        print ("Access Granted, Welcome Mr.", login)
        time.sleep(2)
        ipaddress = input("Enter an ip address you want to ping:")
        print ("Processing ip address...")
        time.sleep(2)
        os.system("ping ", ipaddress)
    elif password2 != password:
        print ("Access Denied")
        print ("Sending S.W.A.T Team")
        time.sleep(2)
        print ("...")
        time.sleep(2)
        print ("Shutting down systems...")
        os.system("cls")
else:
    print ("Access Denied")
    print ("Sending S.W.A.T Team")
    time.sleep(2)
    print ("...")
    time.sleep(2)
    print ("Shutting down systems...")
    os.system("cls")
然后,您要求使用
str
输入

password = random.randint(1000000000, 9000000000)
这种比较永远是错误的

password2 = input("Please enter your password:")
您必须比较同一类型,例如

if password2 == password:
#  ^str         ^int
或者在输入的过程中转换输入

if int(password2) == password:
#  ^int              ^int

random.randint(1000000000900000000)
返回一个
int
<代码>输入(“请输入密码:”)返回一个
str
。使用
int(输入(“请输入您的密码”)

“…当再次输入密码时”-我在代码中只看到一个输入密码的位置。用户必须在哪里再次输入pwd?感谢您的回答,当我输入ip地址时,它给了我一个错误,这是因为我输入的ip地址不正确还是错误?ip地址不是整数,因为它们有多个
字符。我没有将ipaddress变量作为整数输入。我保持不变,所以当您输入ipaddress时,它将作为字符串输入
password2 = int(input("Please enter your password:"))