Question

In: Computer Science

Python 10 - (10 pts) - Implement a program that starts by asking the user to...

Python

10 - (10 pts) - Implement a program that starts by asking the user to enter a userID (i.e., a string). The program then checks whether the id entered by the user is in the list of valid users.

The current user list is: ['joe', 'sue', jamal, 'sophie']

Depending on the outcome, an appropriate message should be printed. Regardless of the outcome, your function should print 'Done.' before terminating.

Here is an example of a successful login:

>>> Login: joe

Welcome back, joe

Done.

And here is one that is not:

>>> Login: john

Unknown users or passwords

Done.

11 – (10 pts) - Using Python, create a random password generator with length = 10 characters. The password should consist of upper- and lower-case letters and digits.

12 - (15 pts) - An acronym is a word formed by taking the first letters of the words in a phrase and then making a word from them. For example, RAM is an acronym for random access memory.

Write a function acronym() that takes a phrase (i.e., a string) as input and then returns the acronym for that phrase.

Note: The acronym should be all uppercase, even if the words in the phrase are not capitalized.

>>> acronym('Random access memory')

'RAM'

>>> acronym('central processing unit')

'CPU'

13 - (10 pts) – Using Python, write a segment of code to populate the table "employee" of the database "EmployeeDB” with the data below. Import your choice of DB connector (import MySQLdb/sqlite3…)

Create the“employee” table with schema = [name, address, age]

Insert this employee: John Doe, 7001 E Williams Field, 32

14 - (20 pts) - Define a class called Animal that abstracts animals and supports three methods:

setSpecies(species): Sets the species of the animal object to species.

setLanguage(language): Sets the language of the animal object to language.

speak(): Prints a message from the animal as shown below.

The class must support supports a two, one, or no input argument constructor.

Then define Duck as a subclass of Animal and change the behavior of method speak() in class Duck.

>>> snoopy = Animal('dog', 'bark')

>>> snoopy.speak()

I am a dog and I bark.

>>> tweety = Animal('canary', ‘tweet’)

>>> tweety.speak()

I am a canary and I tweet

>>> animal = Animal()

>>> animal.speak()

I am an animal and I make sounds.

>>> daffy = Duck()

>>> daffy.speak()

quack! quack! quack!

Solutions

Expert Solution

10 )

Python Code::

'''
This program checks whether the user is a valid user
or not..
'''
userList = ['joe', 'sue', 'jamal', 'sophie']   #initial user list
userName = input(">>> Login: ")   #prompt for user name
if userName in userList:         #condition to check whether the user name entered is in the list
    print("Welcome back,", userName)   #prints msg..
else:
    print("Unknown users or passwords")
    
print("Done.")

SCREENSHOTS::


Related Solutions

Python Implement a program that starts by asking the user to enter a login id (i.e.,...
Python Implement a program that starts by asking the user to enter a login id (i.e., a string). The program then checks whether the id entered by the user is in the list ['joe', 'sue', 'hani', 'sophie'] of valid users. Depending on the outcome, an appropriate message should be printed. Regardless of the outcome, your function should print 'Done.' before terminating. Here is an example of a successful login: >>> Login: joe You are in! Done. And here is one...
Step by step in python Write a program that will keep asking for a user input...
Step by step in python Write a program that will keep asking for a user input (until a blank line is entered) and will inform me whether what I entered was a valid number or not (without crashing). The program should use at least one try/except loop The program should include at least two custom written functions (a main() function can count as one of the two)
What it Looks Like to the User The program will loop, asking the user for a...
What it Looks Like to the User The program will loop, asking the user for a bet amount from 0 to 100 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are:  BAR 7 BAR, 7 7 cherries,...
Design and implement a program that reads a series of 10 integers from the user and...
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, and then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
Write a Python program to implement Vignere Cipher. Take user input to get plain text and...
Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
First, write a program to loop asking for a number from the user until the user...
First, write a program to loop asking for a number from the user until the user inputs a zero or until the user has input 50 numbers. Store each value in an array except the values that are divisible by 5 and display all stored values. Determine how many of the values stored in the array were divisible by 10 and display result. Next, write a function getMinMax that accepts an array of floats and the size of the array,...
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get...
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key. 2.  Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get...
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key. 2.  Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the...
PYTHON: Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663. This is my code, but I cannot figure out where to go from here. #set new number new_number = "" #split number split_num = phone.split("-") for char in split_num[1:2]:...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT