如何使代码重复输入问题?

时间:2019-09-19 13:14:04

标签: python

我已经在If,Elif,Else LogIn系统上工作了大约一天。我是python的新手,我想知道每次有人输入内容时如何重复Input = raw_input(127.0.0.1)语句。这是我的代码。

# Welcome to my app.
import sys
from colorama import Fore, Back, Style 

print "\033[31mWelcome to Nicks Login Prompt. Please enter your ID\033[0m\n"
ID = raw_input("\033[36m127.0.0.1 -> \033[0m")
Password = raw_input("\033[36m127.0.0.1 -> \033[0m")


if ID == "Alex" and Password == "n72kt34h" or ID == "Nick" and Password == "SysTest" or ID == "Mari" and Password == "Test":

    print ("\033[32m \n  Welcome to my assistant program.\n  If you are unaware with how this system works, type Help.\n     For any suggestions message me on Discord.\n \033[0m")
    Input = raw_input("\033[36m127.0.0.1 -> \033[0m")
else:
    print "Your account was not recognized."


if Input == "Help" or Input == "help":
    print "\033[33mWelcome to the Skog assistant.\033[0m\n \033[34mThis software was made so that Nicks friends can have their own platform.\033[0m \n \033[35m Commands are as followed:\033[0m"
    print "     \033[42mType, Discord, Info."

elif Input == "Color":
    print "\033[1;36;40m Bright Cyan"

elif Input == "Discord" or Input == "discord":
    print "\nJoin the server: \033[36mhttps://discord.gg/fAFYCHr\033[0m <- \033[31mWarning: Not for people that are sensitive.\033[0m\n"

elif Input == "Info" or Input == "info":
    print "\n Made by PricklyTrees.\n Version 1.6. \n New updates frequently. \n Suggest stuff on the Discord.\n"

elif Input == "Type" or Input == "type":
    print "\nI'm sorry, but currently I am unable to make the Type service at the moment. To get ready for it, you should make a folder and put this application in it.\n"

else:
    print "Command not found."

1 个答案:

答案 0 :(得分:0)

使用while循环。并从用户那里获得输入,直到他的输入表明退出程序为止。 (F.x“退出”)

ID = raw_input("\033[36m127.0.0.1 -> \033[0m")
while ID != "exit":
  # do what you want here but don't forget to ask for  
  # a new input when you are done processing the previous input
  ID = raw_input("\033[36m127.0.0.1 -> \033[0m")
print("Finish")

PS。我不确定“ \ 033 [36m127.0.0.1-> \ 033 [0m””部分是什么,但是我只是希望它类似于您自己的代码,因此我复制了您的行。 通常,您在该部分中输入“输入您的代码”之类的内容。