简体   繁体   English

如何制作 Python 打印循环

[英]How to make a Python print loop

I need a little bit of help.我需要一点帮助。 I just started programming.我刚开始编程。 I wanted to try to make a sort of computer terminal that would ask for a user and password (For example jcd;bionicman) and when you would write in some sort of loggin that is in the registry, it would show certain text (For example "Welcome Back JC. Denton) But, when I write in the user, it just ends the process. How do I make it so that, when I write in the loggin and press enter, it would show the text, and then ask for another user: Here is an example我想尝试制作一种计算机终端,它会要求输入用户和密码(例如 jcd;bionicman) ,当您输入注册表中的某种登录信息时,它会显示某些文本(例如“欢迎回来 JC. Denton)但是,当我在用户中写入时,它只是结束了过程。我如何做到这一点,当我在登录中写入并按 Enter 时,它会显示文本,然后要求另一个用户:这是一个例子

Program: Enter Loggin
User: jcd;bionicman
Program: Welcome back JC
Program: Enter new Loggin

I know its probably a really simple solution, but everyone has to start somewhere, right?我知道这可能是一个非常简单的解决方案,但每个人都必须从某个地方开始,对吗?

Here is my progress so far:这是我到目前为止的进展:

    password = input()

if password == "jcd;bionicman":
    print("Terminal Accessed. Welcome Back JC")


else:
    print("Unknown Terminal Loggin, Try again.")

while 3 > 2:
    print("Insert Terminal User and Password")
    break
input()

This sort of works, but it only asks for another user once, meaning you can enter a loggin twice before the process ends.这种工作,但它只要求另一个用户一次,这意味着您可以在该过程结束之前输入两次登录。

edit: Adding a while: true, sort of broke something, now when you write a wrong loggin, it wil not say ("Unknown Terminal Loggin, try again") instead it will just ask for a new user, same with a correct loggin.编辑:添加一段时间:真的,有点破坏了一些东西,现在当你写了一个错误的登录时,它不会说(“未知终端登录,再试一次”)而是它只会要求一个新用户,与正确的登录相同.

You should use a While loop.您应该使用 While 循环。 For example, (* Make sure to add a break)例如,(* 确保添加一个中断)

while True:
  print("foo")

What you are trying to accomplish can be done with this code:您可以使用以下代码完成您要完成的工作:

joesPassword
while True:
  continueLoop = input("Hey! Want to continue (Y/n)")
  if continueLoop=="n":
    break
  user = input("Welcome! What is your username? ")
  passw = input("Hello, "+user+"! What is your password? ")
  if passw==joesPassword:
    print("Hey, Joe! You got your password correct!")
  else:
    print("Aw man! Your password is wrong!")

You'll want to use a while loop.您将需要使用while循环。 Put this before your print code:把它放在你的打印代码之前:

while True:

Then, indent the print code.然后,缩进打印代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM