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

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.
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.
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...
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]:...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
Create a matlab program that calculates equivalent cpacitance and charge by asking the user whether the...
Create a matlab program that calculates equivalent cpacitance and charge by asking the user whether the circuit is in paraller , series or combination and then asks for the values of capacitances and voltage. After that it calculates the equivalent capacitance.
1. Write a program that keeps asking the user for a password until they correctly name...
1. Write a program that keeps asking the user for a password until they correctly name it. Once they correctly enter the password, the program congratulates the user and tells them how many guesses it took. Be sure to be grammatically correct with the guess/guesses output. Call the program LastNamePassword. Example (user input in italics) What is the password? monkeys Incorrect. Guess again. dishwasher Incorrect. Guess again. aardvark Correct! You got the password, and it took you 3 guesses to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT