In: Computer Science
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!
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::