Question

In: Computer Science

Please add a statement that requires a number in the password to the following code: #Lab...

Please add a statement that requires a number in the password to the following code:

#Lab on functions
#By Abi Santo
#10/25/20

def get_first_and_last_names():
first = input("Enter your first name: ")
last = input("Enter your last name: ")
return (first.lower(), last.lower())

def create_username(name_list):
uname = name_list[0] +"." + name_list[1]
return uname

def create_password():
passwd = input("Create a new password: ")

#make sure the password has atleast 8 characters
while len(passwd)<8:
print("Fool of a Took! That password is feeble!")
passwd = input("Create a new password: ")

while passwd.lower() == passwd:
print("The password must contain at least one uppercase character")
passwd = input("Create a new password: ")


print("The force is strong in this one...")
print("Your password has been accepted.")
return passwd


def main():
#Get user's first and last name
first_last_name_list = get_first_and_last_names()

#create a username using the first and last name
username = create_username(first_last_name_list)

#ask the user to create a new password
password = create_password()

print("Account configured. Your new email address is: ", username + "@marist.edu")
  
  
main()


please use python

Solutions

Expert Solution

code analysis:

After giving first name and last name.....

If we give "pavan" as passwd. It did not accept since it has less than 8 characters.

Then we give...."pavankumar" as passwd. Since it has atleast 8 characters..it moved on to check whether it has an uppercase character. since it does not..program asked for passwd again.

At this stage I gave "Pavan". The program accepted.though there are less than 8 characters. It's actually worng.

Code:

def get_first_and_last_names():

first = input("Enter your first name: ")

last = input("Enter your last name: ")

return (first.lower(), last.lower())

def create_username(name_list):

uname = name_list[0] +"." + name_list[1]

return uname

def create_password():

passwd = input("Create a new password: ")

while(True):

flag_digit = False

length = len(passwd)

upper_check = (passwd.lower() == passwd)

for symbol in passwd:

if symbol.isdigit():

flag_digit = True

#make sure the password has atleast 8 characters. Otherwise read passwd again from user and check from initial condition

if length < 8:

print("Fool of a Took! That password is feeble!")

passwd = input("Create a new password: ")

continue

#If the passwd has 8 characters. Make sure the passwd also has an upper case character: Otherwise read passwd again from user and check from initial condition

elif upper_check == True:

print("The password must contain at least one uppercase character")

passwd = input("Create a new password: ")

continue

#If the passwd has 8 characters and an uppercase character make sure it also has digit. Otherwise read passwd again from user and check from initial condition

elif flag_digit == False:

print("Password should contain atleast one digit")

passwd = input("Create a new password: ")

continue

#If it satisifies all the conditions...BREAK

else:

print("The force is strong in this one...")

break

print("Your password has been accepted.")

return passwd


def main():

#Get user's first and last name

first_last_name_list = get_first_and_last_names()

#create a username using the first and last name

username = create_username(first_last_name_list)

#ask the user to create a new password

password = create_password()

print("Account configured. Your new email address is: ", username + "@marist.edu")

main()

PLEASE....Rate....If you like the answer......


Related Solutions

Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
(Python Code please) Guess the number! You will add to the program you created last week....
(Python Code please) Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number...
This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
Please take the code below and add some javascript to it. Please use javascript inline. Please...
Please take the code below and add some javascript to it. Please use javascript inline. Please be sure to specify within the webpage with something like 'Click here' too show what was done and how to activate it. Please post in a format that can be directly copied. Thank you in advance HINT: add some fun widgets to the page index-css.html: <!DOCTYPE html> <html lang="en"> <head> <!-- title for web page --> <title>Index-CSS Page</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality for multiplication (*) Adding JUnit tests Add one appropriately-named method to test some valid values for tryParseInt You will use an assertEquals You'll check that tryParseInt returns the expected value The values to test: "-2" "-1" "0" "1" "2" Hint: You will need to cast the return value from tryParseInt to an int e.g., (int) ValidationHelper.tryParseInt("1") Add one appropriately-named method to test some invalid...
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import...
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom66(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public...
code in c++ using the code given add a hexadecimal to binary converter and add a...
code in c++ using the code given add a hexadecimal to binary converter and add a binary to hexadecimal converter #include <iostream> #include <string> #include<cmath> #include<string> using namespace std; int main() { string again; do { int userChoice; cout << "Press 2 for Decimal to Binary"<< endl; cout << "Press 1 for Binary to Decimal: "; cin >> userChoice; if (userChoice == 1) { long n; cout << "enter binary number" << endl; cin>>n; int decnum=0, i=0, remainder; while(n!=0) {...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT