Questions
Runtime efficiency and code simplicity are often competing goals. How can you deal with this problem?...

Runtime efficiency and code simplicity are often competing goals. How can you deal with this problem? Is it possible to have code that is both simple and efficient?

In: Computer Science

"PYTHON" Declare a list that is initialized with six of your favorite sports teams. Print out...

"PYTHON"

Declare a list that is initialized with six of your favorite sports teams. Print out the number of teams to the shell. Use a for loop to print out the teams to the shell.

2. a. Declare a sporting goods list, initially with no elements.
b. Use a while loop to prompt the user for a sporting goods item and append the item to the list.
c. Break out of the loop when the user enters exit; do NOT append the word exit to the list.
d. Write a for s in sport_list loop to print out the elements in the list to the shell.
(BONUS) Add code to handle a ctrl-c exit.

3. a. Create a pressure list which initially contains no elements. b. Using the SenseHat, take 25 pressure measurements and store each measurement as a floating-point number in the list. Be sure to have the program sleep for a second or two between each measurement.
c. After recording the measurements, calculate the average of the pressure measurements- use the sum function and display the average on the SenseHat.

4. Allow the user to enter new sporting goods items at a specific index in the sporting goods list. Prompt the user for the index and the new item’s name.

5. Sort the sporting goods list in ascending order. Use a while loop to print out each item in the sporting goods list.

---Allow the user to delete an item from the sporting goods list. Prompt the user for the item’s name.

-- Sort the sporting goods list in descending order. Use a while loop to print out each item in the sporting goods list.


---a. Create a week_tuple and assign the days of the week as strings to the week_tuple.

b. Print out the elements in the week_tuple.

---a. The following list has been declared as follows:
credit_list = [24,3,15]

b. Convert the credit_list to a tuple named credit_tuple.

c. Print out the elements in the credit_tuple.

---a. Write an initialize_list_values function that takes in a number for the number of elements in a list and an initial value for each element. The function creates a new list and appends the elements with the initial value to the new list.

b. Pass in 5 and 3.4 as arguments to the intital_list_values and store the returned list in data_list.

c. Use a loop to print the elements of the data_list.

---a. Create a tuple named inventory_items_tuple which has Raspberry Pi 3, Raspberry Pi 2, and Raspberry Pi Camera Module.

b. Create a tuple named out_of_stock_items_tuple which has Raspberry Pi Zero. (Hint: add a , after “Raspberry Pi Zero”.)

c. Append these two tuples together into the all_items_tuple. Print out each element in the tuple using a for loop and use the len function to determine the number of elements in the tuple.
  

--a. Create a list of lists consisting of three rows and four columns, which were initially set to 0.
b. Prompt the user to initialize each element in the list of lists.
c. Compute the sum of all of the elements in the list. You may use the sum function.
d. Prompt the user to enter a row number and use a loop to calculate the sum of the elements in the row and print out the sum.

In: Computer Science

If you have downloaded the source code from this book's companion web site, you will find...

If you have downloaded the source code from this book's companion web site, you will find the following files in the Chapter 07 folder: • GirlNames.txt--This file contains a list of the 200 most popular names given to girls born in the United States from the year 2000 through 2009. • BoyNames.txt--This file contains a list of the 200 most popular names given to boys born in the United States from the year 2000 through 2009. Write a program that reads the contents of the two files into two separate lists, allows a user to input either a girl's name, a boy's name, or both, then tells the user whether the name(s) was/were popular between 2000 and 2009. First, the program should prompt the user to choose a girl's name, a boy's name, or both by entering either 'girl', 'boy', or 'both.' Once they have chosen, they should be able to input a name. If the name was a popular name, like Jacob or Sophia, the program should print "Jacob was a popular boy's name between 2000 and 2009." or "Sophia was a popular girl's name between 2000 and 2009." If the name was not a popular name, like Voldemort, the program should print "Voldemort was not a popular boy's name between 2000 and 2009." If the user chooses to input both a girl and boy's name, ask for the boy's name, then the girl's name, and print two statements in the form mentioned above on two separate lines, with the statement about the boy's name coming first. For example, if the user inputs Voldemort and then Sophia, print: Voldemort was not a popular boy's name between 2000 and 2009. Sophia was a popular girl's name between 2000 and 2009.

My code is working perfectly on boy and girl but it only reads that a name was not popular for boy and girl when running both.

def searchBoyName(boysList, name): #Searching for given boy name in list if name in boysList: #If found print("\n " + str(name) + " was a popular boy's name between 2000 and 2009. \n"); else: #If not found print("\n " + str(name) + " was not a popular boy's name between 2000 and 2009. \n"); def searchGirlName(girlsList, name): #Searching for given girl name in list if name in girlsList: #If found print("\n " + str(name) + " was a popular girl's name between 2000 and 2009. \n"); else: #If not found print("\n " + str(name) + " was not a popular girl's name between 2000 and 2009. \n"); def main(): #Reading data from files boysList = open("BoyNames.txt", "r"); girlsList = open("GirlNames.txt", "r"); #Initializing lists boyNames = []; girlNames = []; #Adding boys names for name in boysList: name = name.strip(); boyNames.append(name); #Adding girls names for name in girlsList: name = name.strip(); girlNames.append(name); #Accepting input from user type = input("\n Enter 'boy', 'girl', or 'both':"); #Searching for boy name if type == "boy": # Reading boy name bname = input("\n\n Input a boy name: "); # Searching searchBoyName(boyNames, bname) #Searching for girl name elif type == "girl": #Reading girl name gname = input("\n\n Input a girl name: "); #Searching searchGirlName(girlNames, gname); #Searching for both elif type == "both": #Searching for given boy name in list bname = input("\n\n Input a boy name: "); #Reading girl name gname = input("\n\n Input a girl name: "); if bname in boysList: #If found print("\n " + str(bname) + " was a popular boy's name between 2000 and 2009. \n"); elif bname not in boysList: #If not found print("\n " + str(bname) + " was not a popular boy's name between 2000 and 2009. \n"); #Searching for given girl name in list if gname in girlsList: #If found print("\n " + str(gname) + " was a popular girl's name between 2000 and 2009. \n"); elif gname not in girlsList: #If not found print("\n " + str(gname) + " was not a popular girl's name between 2000 and 2009. \n"); else: print("\n Invalid selection.... \n"); #Calling main function main();

In: Computer Science

'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a...

'PYTHON'

1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass in 150.78 and True. Call the function from within main() and pass in 98.23 and False. Print out the returned discounted cost with two decimal places of precision in the main function.

2. Add annotations and comments to the compute_discount() function. Call the appropriate functions from within main() to display the annotations and comments and print the output.

3. a. Create a new file (module) named camera_picture.py.
b. Write a function, take_picture_effect, that takes two parameters, the filename and an effect.
c. Take a picture with the filename and effect. Use camera.effect to set the effect. Use help(PiCamera) to find the effects which you can apply.
d. Create a second file use_camera.py.
e. Import the take_picture_effect function from the camera_picture module.
f. Prompt the user for the filename.
g. Prompt the user for the image_effect. help(PiCamera) to see the list of image effects.
h. Call the function with the filename and the effect as arguments.

3. Write a function that prints a menu that allows the user to select an effect with a letter. Call the take_picture_effect function with the appropriate arguments.
a. cartoon
b. pastel
c. emboss
etc.

(BONUS)
a. Create a new file (module) named light_sound.py.
b. Write a function, alert_fun that takes three parameters, the GPIO pin for the LED, the GPIO pin for the Buzzer, and the duration of the light to be on and the buzzer to sound.
c. Create a second file use_light_sound.py.
d. Import the alert_fun function from the light_sound module.
e. Prompt the user for the GPIO pin for the LED, the GPIO pin for the Buzzer, and the duration.
d. Call the function with the duration as an argument.

In: Computer Science

Argue for or against the following statement: "Robots are better than humans in all business capacities."

Argue for or against the following statement: "Robots are better than humans in all business capacities."

In: Computer Science

Write a Java application, and an additional class to represent some real-world entity such as a...

Write a Java application, and an additional class to represent some real-world entity such as a technology item, an animal, a person, a vehicle, etc. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods).

The class will:

  1. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to represent a lamp might include color, price, height, numBulbs, batteryOperated. Each of these 5 variables need a data type.

  2. Include at least three different constructor methods, in addition to the default constructor (0 argument constructor). The constructor is a function (method) which allocates memory and initialized the member variables specified in (a.).

  3. Include getters/setters for to serve as as mutators and accessors for each variable. Name these appropriately such as setColor & getColor, setPrice & getPrice, setHeight & getHeight, setNumBulbs and getNumBulbs, and setBatteryOperated & getBatteryOperated.

  4. Create a member function showValues() to display the values of an object in a formatted manner.

  5. Create at least 2 other member functions (methods) for the class that will perform some operation on the data (i.e. calculations or additional report/display of output). For example, turnLampOn, changeBulb, etc.

The Java application class (with a main method) will:

  1. Instantiate at least three objects (using each of the constructors at least once) with your program.

Note: Set the remaining data with the mutator methods.

  1. Store the data from the individual objects into an ArrayList (or some other dynamic data structure of objects.

  2. Utilize the showValues() method and each of the two methods on each of your objects to demonstrate their use.

Required Output: Generate output samples demonstrating all of your member functions, adequately testing them and showing their functionality (i.e. inputting values, outputting values (displaying them), performing calculations, etc.).

In: Computer Science

SDS operates stores in the following cities: Melbourne, Ballarat, Geelong, Sydney, Newcastle, Brisbane, Adelaide and Perth....

SDS operates stores in the following cities: Melbourne, Ballarat, Geelong, Sydney, Newcastle, Brisbane, Adelaide and Perth. Stores are referenced by store number. SDS also keeps store name, street, city, state, postcode, telephone, and manager's details. Each store is assigned a supervising store where major customer complaints are referred, training is conducted, and server applications and help desk functions are located. The supervising store currently supervises stores within its own state boundaries but this is not necessarily going to continue in the future.

When a customer rings with a complaint, details of the complaint are to be recorded. The details include the date the complaint was made, the employee id of the person recording the complaint, the customers first name, last name, street address, town, state, postcode and phone numbers. A customer may provide the employee taking the call with more than one type of phone number and include mobile, fax, home and office numbers. A complaint may be one of three different types. It may be related to the store, one or more employees or product(s) of the store. If a complaint is about the store a short description of the complaint is recorded and it is referred to the manager. If the complaint is about employees of the store, the ID(s) of the employees involved in the complaint is recorded, along with a short description of the problem. If the complaint is about products, the product id, the number of items and a short description are recorded. A customer may be involved in a number of complaints. Currently, complaints are provided with individual identification numbers.   Once a complaint has been resolved, the date that the complaint was closed is recorded.

Whilst the complaint is open all contact with the customer is recorded. Details of the date, time, the employee making contact, the type of contact (phone, fax, email or personal visit) and a short description of the contact are all recorded.

If the complaint is about a product, a replacement is normally provided. The store likes to keep track of all of the products replaced and the date the items were sent to the customer.

The store would also like you to interface your database with its products table in its inventory database. The products table has fields including ProductId, ProductName, ProductDescription, ProductUnitCost.

You are required to design (using an E-R diagram) an entity-relationship model of the problem, convert the model into a relational model, assess the normal form of each schema and write SQL queries that will answer the following queries.

  1. An alphabetically sorted list of all customers who have made a complaint. Only customer number and name are required.
  2. A more complete customer list sorted by customer id. It should contain customer id, name, address and all available phone numbers.
  1. The date on which the most recent complaint has been made. The date itself will suffice.
  2. A list of all complaints still open. Displaying complaint number will be sufficient.
  3. A list of all complaints sorted by the type of the complaint. Displaying the complaint identification number, the customer id, the date the complaint was made, and the type of complaint will be sufficient.
  4. A list of all products involved in customer complaints. Display the product id and name, sort this using the product name.
  5. A total of the cost price of all products replaced. Displaying the total amount will be sufficient.
  6. A list of all customers with more than 4 complaints. The customer id and name should be displayed.
  7. A list showing the total number of complaints made about employees in each department. Displaying the department id and the total number of complaints is sufficient.
  8. A customer list for all complaints still open that shows when the customer was last contacted. The customer id, name, last date of contact and type should be displayed, the list should be listed in descending date order.

In: Computer Science

Formulate different metrics that could be used to compare the performance of the robotic system with...

Formulate different metrics that could be used to compare the performance of the robotic system with the presently used manual system

In: Computer Science

Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...

Struct PERSON Assignment

Outcomes:

Demonstrate the ability to create structs using typedef
Demonstrate the ability to create an array of structs
Program Specifications:

DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON.

Create a struct using the typedef command for a DATE.

Create a struct for a PERSON with the following fields.

name [this will be a string]
birthdate [this will be a DATE]
gender [this will be a char]
annualIncome [this will be either float or double, your choice]
Create three variables of type PERSON. Create a function that populates the data for each person (all 3 of them). Create a function that outputs all data about each of the people in a nice formatted manner.

Data Validation:

All dates entered must be validated. Make sure you account for the number of days in each month, the fact that there are exactly 12 months and every four years there is a leap year.

The name for each PERSON will be stored in sentence case.

The gender will either be M, F, or O.

The annual income will between 0 dollars and 1 million dollars.

Submission Requirements:

Requirements will be same as the first assignment which will be the same for all future assignments except that you do NOT NEED a design tool for this assignment.

DO NOT:

Use global variables, in this or any program ever.
Use goto statement(s), in this or any program ever.

In: Computer Science

What factors should be considered in selecting a design strategy? (object oriented design and analysis) Name...

  1. What factors should be considered in selecting a design strategy? (object oriented design and analysis)
  2. Name different computing Client-Server architectures and give examples of the architectures.
  3. What are the main principles for User Interface Design? Describe any one of the principles in detail.
  4. Name five steps in the user interface design process.
  5. Describe types of navigation control in the user interface.
  6. Name basic principles of output design.

In: Computer Science

discuss which is better: Boolean algebra or K-map? What are the limitations of Karnaugh Maps? Explain...

discuss which is better: Boolean algebra or K-map?

What are the limitations of Karnaugh Maps? Explain with an example.

In: Computer Science

C++ good documentation as well as explanations would be great. I need the code to be...

C++

good documentation as well as explanations would be great. I need the code to be written without (#include if possible. Please don't just copy and paste someone else's answer.

In this HW assignment we will simulate a car wash and calculate the arrival time, departure time and wait time for each car that came in for a car wash. We will use the following assumptions about our car wash:

  1. Each car takes 3 minutes from start of the car wash to the end.

  2. Only one car can be in the car wash at a time. This mean that if a car enters a car wash at 1:00 PM then no car can enter the car wash till 1:03 PM.

  3. Simulation will start at the opening time of the car wash and will be represented with 0. We do not not care about the actual time as we are interested in time intervals. Example: a car arrived at time 5 means that car arrived 5 minutes after the opening of the car wash.

  4. We will assume that car wash opens at 8:00 AM and closes at 5:00 PM. This implies that car wash is open for 9 hours or 540 minutes.

  5. Simulation will run for number of minutes given by SIMULATION_END_TIME. We will set it to 540 as our car wash is open for 540 minutes.

  6. The arrival time of cars will be stored in the file named arrival_time.txt. The file will list the arrival time of one car per line. The numbers of cars that will come to our car wash will be variable. You can have an input file with arrival time for 5 cars or for 100 cars. Example of input file is given at the end of this handout. Any car that arrives after the closing time given by SIMULATION_END_TIME will not be serviced.

  7. The program will display the following information about each car: car number, arrival time, car wash start time, departure time, wait time, and total time in form of a table.

    1. Arrival time, car wash start time, and departure time will be in minutes from the opening of the car wash.

    2. Arrival time and car wash start time may be same if there are no cars in the car wash.

    3. Wait time is car wash start time – arrival time.

    4. Total time is the departure time – arrival time.

  8. The program will also display the following statistics: total wait time, average wait time, total car wash use time, percentage of time car was was in use.

  9. Hint: Use a Car class to keep track of car number, car arrival time and car wash start time.

Sample Input File:

1
2
4
10
13
15
16
75

Sample Output (Set SIMULATION_END_TIME to 60 for this example):

Opening Time: 8:00 AM (0 minutes)

Closing Time: 9:00 AM (60 minutes)

Start of Simulation

Car Number

Arrival Time

Car Wash
Start Time

Departure Time

Wait Time

Total
Time

1

1

1

4

0

3

2

2

4

7

2

5

3

4

7

10

3

6

4

10

10

13

0

3

5

13

13

16

0

3

6

15

16

19

1

4

7

16

19

22

3

6

8

75

Car arrived after closing time and was not served.

End of Simulation

Statistics:

Total wait time: 9 minutes

Average wait time: 1 minutes and 17 seconds

Total car wash use time: 21 minutes

Percentage of time car was was in use: 35%

Notes:

  1. Use Queue STL to keep track of the arrival time.

  2. Multiple cars can arrive at same time.

  3. Input file is sorted by arrival time.

Sample arrival_time.txt:

0
3
10
11
11
14
17
17
24
25
35
38
39
45
48
50
52
52
60
62
68
74
86
99
100
118
124
130
133
143
147
150
175
177
182
185
191
195
200
219
230
231
232
233
248
275
281
293
297
302
305
309
310
315
322
327
327
330
339
342
347
352
371
375
375
384
395
398
402
406
414
417
425
432
441
441
450
453
456
458
462
465
466
475
477
480
482
488
491
508
509
513
513
517
519
520
522
524
526
529
532
537
538
539
540
541

In: Computer Science

C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...

C++

A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.

In: Computer Science

create a file with 1000 alphanumeric ones written one per line. Write a program in python...

create a file with 1000 alphanumeric ones written one per line. Write a program in python that randomly selects 100 of them, holds the index of each alphanumeric, adds the hash of the previous 100 and tries to find a random alphanumeric so that if it adds it to the list of indicators the SHA256 of the whole to have 10 zeros at the end. You start with the original Hash: 1111..111

my solution so far:

import random
import string

# here i create a file with 1000 alphanumerics
f = open("key.txt", "w")
randomstring = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(1000))

for char in randomstring:
f.write(char)
f.write("\n")
f.close()

with open("key.txt") as m:
sample_of_100 = random.sample(m.readlines(),100)
print(sample_of_100)

idx = []
sample_str = ' '.join([str(elem) for elem in sample_of_100])
for num, name1 in enumerate(sample_str, start=1):
for num, name2 in enumerate(randomstring, start=1):
if name1 == name2:
idx = name2

print("index {}: {}" .format(randomstring.index(name1), idx))

In: Computer Science

in a gui ' in java write a program that draws equal a simple fence with...

in a gui ' in java write a program that draws equal a simple fence with vertical, spaced slats backed by two boards. Behind the fence show a simple house support Make sure the in the und. house is visible between the slats in the fence.

In: Computer Science