The nutrition.py program (attached) creates a dictionary of food items (a mix of fruit and meat items) and displays their corresponding information. The dictionary has the food item code, and Food object as key and value respectively. Write the missing code, in the designated locations, in order for the program execution to yield the following output when the input number of food items is 5:
Enter number of food items:
5
Type: Fruit
Category: Apples & Pears
Code: 1012030
Name: Fruit_0
Sugar: 10g
Type: Meat
Category: Chicken
Code: 1012031
Name: Meat_1
Protein: 21%
Type: Fruit
Category: Berries
Code: 1012032
Name: Fruit_2
Sugar: 12g
Type: Meat
Category: Beef
Code: 1012033
Name: Meat_3
Protein: 23%
Type: Fruit
Category: Citrus
Code: 1012034
Name: Fruit_4
Sugar: 14g
nutrition.py file
import random
class Food:
FRUIT_CATEGORIES =["Apples & Pears","Citrus","Berries"]
MEAT_CATEGORIES = ["Beef","Chicken","Fish"]
def __init__(self,code,name,category):
self.code = code
self.name = name
self.category = category
def info(self):
print('\nType:',type(self).__name__)
#TODO
class Fruit(Food):
# Add code for the __init__ function
def info(self):
super(Fruit,self).info()
print('Sugar:',str(self.sugar)+"g") # Sugar content
class Meat(Food):
# Add code for the __init__ function
def info(self):
super(Meat, self).info()
print('Protein:',str(self.protein)+"%") # Protein content
# Enter the number of food items
s = input("Enter number of food items:\n")
n = int(s)
foods = dict()
for i in range(0,n):
code = "101203"+str(i)
rd = i % 3
if i % 2 == 0:
food = Fruit(10+i%10,code,"Fruit_"+str(i),Fruit.FRUIT_CATEGORIES[rd])
else:
food = Meat(20+i%10,code,"Meat_"+str(i),Fruit.MEAT_CATEGORIES[rd])
foods[code] = food
keys = list(foods.keys())
keys.sort()
for key in keys:
foods[key].info()In: Computer Science
c++
/////////////////////////////////////////////////////////////////////////
need to be named Subsequences.h and pass test cpp file SubsequenceTester.cpp at the end of this question.
This assignment will help you solve a problem using recursion
Description
A subsequence is when all the letters of a word appear in the relative order of another word.
This assignment you will create a Subsequence class to do the following:
Hints
Think about the following questions to help you set up the recursion...
Submission
To get you thinking of data good test cases, only the example test cases have been provided for you in the SubsequenceTester.cpp. It is your responsibility to come up with several other test cases. Think of good ones
////////////////////////////////////////////////////
SubsequenceTester.cpp
#include <iostream>
#include "Subsequences.h"
using namespace std;
void checkCase(string, string, string, bool);
int main()
{
/**
Add several more test
cases to thoroughly test your data
checkCase takes the
following parameters (name, word, possible subsequence, true/false
it would be a subsequence)
**/
checkCase("Case 1: First Letter", "pin",
"programming", true);
checkCase("Case 2: Skipping Letters", "ace",
"abcde", true);
checkCase("Case 3: Out of order", "bad",
"abcde", false);
return 0;
}
void checkCase(string testCaseName, string sub, string sentence,
bool correctResponse){
Subsequences s(sentence);
if(s.isSubsequence(sub) ==
correctResponse){
cout << "Passed "
<< testCaseName << endl;
}
else{
cout << "Failed "
<< testCaseName << ": " << sub << " is "
<< (correctResponse? "": "not ") << "a subsequence of "
<< sentence << endl;
}
}
In: Computer Science
Activity 1 - Network Design Proposal
In this section, you are required to write a Network Design Proposal. You will need to: 1. Describe the network design scenario that needs to be addressed. 2. Provide a network design solution. 3. Write a complete network design proposal. 4. Develop (implement) a high‐level solution showing important components of the solution using a virtualization tool.
In: Computer Science
What is the output of the following piece of Java code?
int id = 4;
double grossPay = 81.475;
String jobType = "Intern";
System.out.printf("Id: %d, Type: %s, Amount:%.2f", id,grossPay,jobType);
Select one:
Error
Id: 4, Type: Intern, Amount: $81.475
Id: 4, Type: $81.475, Amount: Intern
Id: 4, Type: $81.48, Amount:Intern
Id: 4, Type: Intern, Amount: $81.48
In: Computer Science
Post a two- paragraph summary in your own words, of Walden's policy on academic integrity. Identify three types of academic integrity violations, and explain what stidents can do to avoid them.
In: Computer Science
Code in Python. You can only use while loops NOT for loops.
Program 1: cost_living
In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note: this program requires no input).
Program 2: discount
A discount store is having a sale where everything is 15% off. Write a program to display a table showing the original price and the discounted price. This program requires no input and your table should include headings and the original prices should go from 99 cents to $9.99 in increments of 50 cents.
Program 3: numbers
Write a program to input a sequence of 8 integers, count all the odd numbers and sum all the negative integers. One integer is input and processed each time around the loop.
In: Computer Science
Pseudo flowchart for additional code to be added to the program:
In: Computer Science
How can I do this in python ???
In order to create the Exam Result objects correctly, one must find
the student object and the subject object that the exam result
should refer to. The distributed code contains O (n) methods that
perform sequential searches to find them in the lists. Create new
implementations of oving7. find _student and oving7.find_ topic
that is more effective.
oving7. find _student:
def find _student (student no, student list):
for student in student list:
if
student.get_studentnumber () == studentnr:
return
student
return None
oving7.find_ topic:
def find _ topic (topic code, topic list):
for subject in subject list:
if topic.get_
topic code () == topic code:
return
topic
return None
In: Computer Science
Situation: You suspect there is a virus on your computer. However, you cannot seem to remove this virus using standard software tools. During your analysis of the computer system, you find some interesting information in the Master Boot Record that does not appear to be part of the original boot loader process.
Question: If this is the case, what kind of virus might this be, where do you think it resides, and what steps could you take to erase the virus?
In: Computer Science
Suppose that the packet length is L= 1000 bytes, and that the link transmission rate along the link to router on the right is R = 1000 Mbps.
1. What is the transmission delay (the time needed to transmit all of a packet's bits into the link) (in milliseconds)?
I know that the answer to 1. is ---> The link transmission delay = L/R = 8000 bits / 1000 Mbps = 0.008 msec.
2. what is the maximum number of packets per second that can be transmitted by the link?
I need to know how to calculate 2. above, please help.
In: Computer Science
a) The capacity of a memory chip is specified as 64K x 8 bits. Find out the address lines & the data lines for the chip. b) A memory block has 20 address lines & 16 data lines. Specify its capacity c) Assume a 32-bit microprocessor is to be used in a computer system, what is the size of its address bus, data bus, control bus and the registers if it needs to access up to 32GB of data? Assume that each memory locations can store a 32-bit word.
In: Computer Science
An IPv4 Layer 3 router that uses 32-bit host addresses has four output interfaces, which are numbered 0 through 3. Packets are forwarded to the link interfaces using the following rules:
Destination Address Range Output Link
Interface
00000010 00000000 00000000 00000000
through
00000010 00011111 11111111 11111111 0
00000010 00100000 00000000 00000000
through
00000010 00100001 11111111 11111111 1
00000010 01000010 00000000 00000000
through
00000010 01000011 11111111 11111111 2
all other addresses 3
a. Construct a forwarding table that has no more than five entries
and uses longest prefix matching.
b. Describe how your forwarding table determines the appropriate
link interface
For the following incoming datagram destination addresses, describe
which rule is used, and to which port interface the datagram is
forwarded:
i) 00000010 00001000 11000011 00111100 (binary octets)
ii) 00000010 00001000 11000011 00111100 (binary octets)
iii) 10.0.3.1 (base-10 octets)
iv) 2.65.3.41 (base-10 octets)
v) 2.34.225.200 (base-10 octets)
In: Computer Science
You must write functions permute(...) and permuteAux(...) by analogy with the the functions enumerate(....) and enumAux(....). Basically, the changes are to implement the "without replacement" condition: you must keep track of which letters have been used using a Boolean list in previous stages of the recursion (e.g., B[0] will be true if at an earlier stage of the recursion, 'A' has already been inserted into X; simply don't do the recursive call if that letter has been used).
Print out the sequences for permute(4,3)
CODE FOR enumerate and enumAux
letter = [chr(i) for i in range(ord('A'),ord('Z')+1)] =
def enumerate(N,L):
X = [0] * L
enumAux(N,X,0)
def enumAux(N,X,I):
if(I >= len(X)):
print(X)
else:
for j in range(N):
X[I] = letter[j]
enumAux(N,X,I+1)
enumerate(3,2)
OUTPUT:
['A', 'A'] ['A', 'B'] ['A', 'C'] ['B', 'A'] ['B', 'B'] ['B', 'C'] ['C', 'A'] ['C', 'B'] ['C', 'C']
In: Computer Science
How do you write this code in JavaScript inside the head?
In: Computer Science
Write a Python module that must satisfy the following-
Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less than the second parameter’s index.
Define a function named rinsort. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall sort the elements of the list from position 0 to the position corresponding to the second parameter, in ascending order using insertion sort. This function must be recursive.
In: Computer Science