Is there a way to go back to the beginning of a function using an if gate?
TristanMisja (8)

NOTE: This is only a sample of the code, and it won't show tabs.

import sys
import os
import string
import math
import colorama
import time

def login():
global username
global password
uy = None
username = input("What is your username?\n\t")
uy = input("Username is " + username + ". Is this true? (y/n)")
if uy == "y":
elif uy == "n":
#This is where I want it
password = getpass.getpass("What is your password?\n\t")
cp = getpass.getpass("Confirm your password:\n\t")
if cp == password:
#This is also where I want it

You are viewing a single comment. View All
heyitsmarcus (287)

What you really want to do is restructure your logic just a bit especially in the first part where you want to start over. Instead of saying:

if uy == "y":
elif uy == "n":

Do something like:

if uy == "n":
elif uy == "y":
  #continue on with the rest of the password code

And then in the bottom of the script you could just call login() again to restart the process.

If this helped solve your problem, please consider upvoting and marking my answer as the accepted answer to close this question. I will continue to answer any questions you might have.

TristanMisja (8)

@heyitsmarcus Ok I'll test this I'm just not sure if you can use a function inside itself... but thx!

heyitsmarcus (287)

@TristanMisja You absolutely can do that. Here is a repl with the code I talked about: