You can use str.translate and str.maketrans

>>> s = 'mypassword'
>>> s.translate(s.maketrans('iamBo', '!@M8.'))
'[email protected]'
Answer from Jab on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › wgu learn python 6.15.1: lab: password modifier
r/learnpython on Reddit: WGU Learn Python 6.15.1: LAB: Password modifier
May 27, 2022 -

Strange results. There is a lab where we are to take input and alter the input.

word = input()
password = ''
i = 0

while i < len(word):
    if word[i] == 'i':
        password = password + '1'
    elif word[i] == 'a':
        password = password + '@'
    elif word[i] == 'm':
        password = password + 'M'
    elif word[i] == 'B':
        password = password + '8'
    elif word[i] == 's':
        password = password + '$'
    else:
        password == password + word[i]
    i = i + 1
password = password + '!'
print(password)

This code 'works' but it is dropping the items on in the while loop.

Check this out, the code below works as expected:

word = input()
password = ''
i = 0

while i < len(word):
    if word[i]=='i':
       password +='1'
    elif word[i]=='a':
       password +='@'
    elif word[i]=='m':
       password +='M'
    elif word[i]=='B':
       password +='8'
    elif word[i]=='s':
       password +='$'
    else:
        password += word[i]
    i +=1
password = password + '!'
print(password)

The only difference is using the shorter += way of making a variable equal to itself and the other item.

output from top code is

mypassword

M@$$!

Output from bottom code is

mypassword

Myp@$$word!

:O!!!! What gives? What am I missing?

🌐
Reddit
reddit.com › r/learnpython › password modifier
r/learnpython on Reddit: Password modifier
September 30, 2022 -

Hello, everyone! I have a question. I'm a beginner in Python and I am currently taking an introduction to Python class. One of our assignments this week is to create a password Modifier.

Here's the assignment.

Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "!" to the end of the input string.

  • i becomes 1

  • a becomes @

  • m becomes M

  • B becomes 8

  • s becomes $

Ex: If the input is:

mypassword 

the output is:

Myp@$$word! 

I managed to pass the assignment but I wasn't able to include the append function. I am assuming it wants me to store the values inside a list and then append the '!' at the end. I am unsure however to store each item inside a list.

Here's what I came up with.

word = input()

password = ''

for i in word:

password = ''

if i == 'i':

password += '1'

print(f'{password}', end='')

continue

elif i == 'a':

password += '@'

print(f'{password}', end='')

continue

elif i == 'm':

password += 'M'

print(f'{password}', end='')

continue

elif i == 'B':

password += '8'

print(f'{password}', end='')

continue

elif i == 's':

password += '$'

print(f'{password}', end='')

continue

else:

print(f'{i}', end='')

print(f'!', end='')

What could I have done differently?

Sorry for the long post. I just want to try and learn as much as I can.

🌐
GitHub
github.com › Immaridel › WGU-C859 › blob › master › LAB-Ch6-passwordModifier.py
WGU-C859/LAB-Ch6-passwordModifier.py at master · Immaridel/WGU-C859
- i becomes 1 · - a becomes @ - m becomes M · - B becomes 8 · - s becomes $ Ex: If the input is: mypassword · the output is: Myp@$$word! Hint: Python strings are immutable, but support string concatenation.
Author: Immaridel
🌐
Studocu
studocu.com › southern new hampshire university › intro to scripting › 4.15 lab password modifier
4.15 LAB Password modifier - 4 LAB: Password modifier Many user-created passwords are simple and - Studocu
August 11, 2022 - 4.15 LAB Password modifier 4.15 lab: password modifier many passwords are simple and easy to guess. write program that takes simple password and makes it
🌐
Studocu
studocu.com › southern new hampshire university › intro to scripting › lab 4.15 - it 140: password modifier instructions & details
LAB 4.15 - IT 140: Password Modifier Instructions & Details - Studocu
March 28, 2024 - simple password and makes it stronger by replacing characters using the key below, and by ... Hint: Python strings are immutable, but support string concatenation.
Find elsewhere
🌐
AssignmentCache
assignmentcache.com › home › sof › python › cyb130 object-oriented scripting language › cyb/130 week 3 python lab 4.15: password modifier
CYB/130 Week 3 Python LAB 4.15: Password modifier - AssignmentCache
December 31, 2023 - Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending “q*s” to the end of the input string. i becomes ! a becomes @ m becomes M B becomes 8 o becomes .
🌐
Studocu
studocu.com › southern new hampshire university › intro to scripting › lab 4.15: python password modifier and character count activities
LAB 4.15: Python Password Modifier and Character Count Activities - Studocu
October 19, 2024 - This will Develop mode Submit mode submit your program for Submit for grading Coding trail of your work What is this? min: 2 atest submission 5:41 PM FDT 00 Supmission passed all tests Total score EX: IT the input IS: mypassword the output is: Hint: Python strings are immutable, but support string concatenation. Store and build the stronger password in the given password variable. 599554 qx3zqy7 LAB ACTIVITY 4.15: LAB: Password modifier main Load default template 1 word input ( ) 2 password I 3 4 word word. replace 5 word word. replace 6 word word.
🌐
CliffsNotes
cliffsnotes.com › home › computer science
Section 4.15 - IT 140 PASSWORD MODIFER (pdf) - CliffsNotes
July 12, 2024 - Computer-science document from Southern New Hampshire University, 3 pages, 3/27/24, 7:49 PM Section 4.15 - IT 140: Introduction to Scripting | zyBooks 4.15 LAB: Password modifier Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters us
🌐
Course Hero
coursehero.com › file › 187054810 › Section-615-C-859-Introduction-to-Programming-in-Pythonpdf
Section 6.15 - C 859 Introduction to Programming in ...
Instant access to millions of Study Resources, Course Notes, Test Prep, 24/7 Homework Help, Tutors, and more. Learn, teach, and study with Course Hero. Get unstuck.
🌐
Panel Essays
read.donepapers.com › home › 2022 › june › 22 › 3.15lab: password modifier many user-created passwords are simple...
3.15LAB: Password modifier Many user-created passwords are simple… - Panel Essays
June 22, 2022 - 3.15 LAB: Password modifierMany ... to the end of the input string.i becomes 1a becomes @m becomes MB becomes 8s becomes $Ex: If the input is:mypasswordthe output is:Myp@$$word!Hint: Python strings are immutable, but support string concatenation....
🌐
Course Hero
coursehero.com › metropolitan state university of denver › it › it 140
IT 140 4.15.1 Password modifier.docx - IT 140 Intro to Scripting Southern New Hampshire University Week Four 4.15.1: LAB: Password modifier word = | Course Hero
December 4, 2020 - IT 140Intro to ScriptingSouthern New Hampshire UniversityWeek Four4.15.1: LAB: Password modifierword = input()password =''for x in word:if x == 'i':password += '!'elif x == 'a':password += '@'
🌐
YouTube
youtube.com › watch
Python Lab Password modifier - YouTube
LAB: Password modifierPythonMany user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by r...
Published: March 2, 2024