Hey so i've decided to try out writing some stuff in python after a while. My approach to this probably isn't the most efficient, but i'm sure you guys will see what i'm trying to do.

I'm having troubles with the last part of the program with my askForRestart function.

Anyways, here's the code -

``````import time
import random
import sys

letters = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']
numbers = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

generateAgain = False

def takeInput():
while True:
passwordLengthTemp = input('Enter the length of the password you want:\n    ')
break
elif(passwordLengthTemp.isdigit() == False or int(passwordLengthTemp) < 1 or int(passwordLengthTemp) > 15):
print('Input is either not a digit, is greater than 15 or is less than 1. Please correct this')

def generateLetter():
randomLetter = letters[random.randint(0, len(letters))]
return randomLetter

def generateNumber():
randomNumber = numbers[random.randint(0, len(numbers))]
return randomNumber

def generateRandom():
randomTemp = random.randint(0,1)
return randomTemp

def generatePass():
randomTemp = 0
randomTemp = generateRandom()
if(randomTemp == 1):
if(randomTemp == 0):

global generateAgain
exitCounter = 5
userInput = 0
while True:
userInput = input('\nInput 1 for another password of the same length - or 2 to exit the program\n   ')
if(userInput == 1):
generateAgain = True
break
elif(userInput == 2):
while(exitCounter > 0):
print('Exiting in ' + str(exitCounter))
exitCounter -= 1
time.sleep(1)
sys.exit()
elif(userInput.isdigit() == False):
print('Invalid input. Try again.')

def run():
while True:
takeInput()
break
while True:
generatePass()
if(generateAgain == True):
break

run()
``````
3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by woooee

No your program does not make sense for me, why would you do

``````def resetPassword():

``````

``````password = ''
``````

And you are using global everywhere and do not pass parameters in and return values out of funcitions.

Edited by pyTony

True that.... everything's a mess in here. Disregarding the resetPassword thing - what do i need to do to sort this out?

Simplify and build step by step. Here is functional start.

``````import random
from string import ascii_lowercase as letters # or ascii_letters for both cases

digits = '23456789' # digits which do not mix up with letters

def generatePass(length):
return ''.join( # letters and digits with 50/50 chance for each type
(random.choice(letters if random.randint(0,1) else digits)
for count in range(length)))

test = 8
print(generatePass(test))
``````

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.