-2

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

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.

Adam Smith
  • 52,157
  • 12
  • 73
  • 112
  • 2
    Please share the code you have tried so far. – shreyasm-dev Oct 06 '20 at 16:21
  • Please edit your question and attach your codes – Yeshwin Verma Oct 06 '20 at 16:22
  • Where is your reserch – Yeshwin Verma Oct 06 '20 at 16:24
  • https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response – Tomerikoo Oct 06 '20 at 16:24
  • I added research –  Oct 06 '20 at 16:25
  • 2
    `but everyone has to start somewhere, right?` yes but SO should be your last resort. Read books, read the documentation, search the internet, look up tutorials on YouTube even. SO it not a python tutorial website. – Alex Mandelias Oct 06 '20 at 16:43
  • [How to debug small programs.](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) | [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/843953) | [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/a/261593/843953) – Pranav Hosangadi Oct 06 '20 at 17:09
  • Do not vandalize your posts. By posting on this site, you've irrevocably granted the Stack Exchange network the right to distribute that content under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/) for as long as it sees fit to do so. For alternatives to deletion, see: [I've thought better of my question; can I delete it?](https://stackoverflow.com/help/what-to-do-instead-of-deleting-question) – Sabito stands with Ukraine Dec 23 '20 at 21:07

2 Answers2

1

You should use a While loop. 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!")
  • 1
    Fun fact, if you're using a modern version of Python (3.6+) you can use f-strings to make this string interpolation better looking. Instead of `"Hello, "+user+"! What is your password? "` you can write `f"Hello {user}! what is your password? "`. Alternatively, even old versions of Python support `str.format`. `"Hello, {}! what is your password? ".format(user)` – Adam Smith Dec 23 '20 at 21:10
-1

You'll want to use a while loop. Put this before your print code:

while True:

Then, indent the print code.

Seth
  • 2,214
  • 1
  • 7
  • 21
  • 1
    This is an infinite loop... This is bad advice without seeing the actual code... Please try to answer only well-asked questions. Right now the question is too general. You can ask the OP for clarifications in the comments – Tomerikoo Oct 06 '20 at 16:23