Answer:
The generator function using yield from:
def scale(s, k):
yield from map(lambda x: x * k, s)
Another way to implement generator function that works same as above using only yield:
def scale(s, k):
for i in s:
yield i * k
Explanation:
The complete program is:
def scale(s, k):
"""Yield elements of the iterable s scaled by a number k.
>>> s = scale([1, 5, 2], 5)
>>> type(s)
<class 'generator'>
>>> list(s)
[5, 25, 10]
>>> m = scale(naturals(), 2)
>>> [next(m) for _ in range(5)]
[2, 4, 6, 8, 10]
"""
yield from map(lambda x: x * k, s)
If you want to see the working of the above generator function scale() as per mentioned in the above comments, use the following statements :
s = scale([1, 5, 2], 5)
print(type(s))
#The above print statement outputs:
#<class 'generator'>
print(list(s))
#The above print statement outputs a list s with following items:
#[5, 25, 10]
The function def scale(s, k): is
def scale(s, k):
yield from map(lambda x: x * k, s)
This function takes two parameters i.e. s and k and this function yields elements of the given iterable s, scaled by k.
In this statement: yield from map(lambda x: x * k, s)
yield from is used which allows to refactor a generator in a simple way by splitting up generator into multiple generators.
The yield from is used inside the body of a generator function.
The lambda function is a function that has any number of arguments but can only have one expression. This expression is evaluated to an iterable from which an iterator will be extracted. This iterator yields and receives values to or from the caller of the generator. Here the expression is x: x * k and iterable is s. This expression multiplies each item to k.
map() method applies the defined function for each time in an iterable.
The generator function can also be defined as:
def scale(s, k):
for i in s:
yield i * k
For the above example
s = scale([1, 5, 2], 5)
def scale(s,k): works as follows:
s = [1, 5, 2]
k = 5
for loop iterates for each item i in iterable s and yields i*k
i*k multiplies each element i.e 1,5 and 2 to k=5 and returns a list
At first iteration, for example, i*k = 1 * 5 = 5, next iteration i*k = 5*5 = 25 and last iteration i*k = 2*5 = 10. So the output. So
s = scale([1, 5, 2], 5) In this statement now s contains 5, 25 and 10
print(list(s)) prints the values of s in a list as: [5, 25, 10] So output is:
[5, 25, 10]
Giving BRANLIEST IFFF CORRECT
Which type of chart or graph shows the contribution of each item in a total of 100%?
Bar graph
Column chart
Line graph
Pie chart
Answer:
pie chart
Explanation:
pie chart shows percentage per item
Answer:
pie chart
Explanation:
Write a method named coinFlip that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of whitespace-separated tokens. Assume that the input file data represents results of sets of coin flips. A coin flip is either the letter H or T, or the word Heads or Tails, in either upper or lower case, separated by at least one space. You should read the sequence of coin flips and output to the console the number of heads and the percentage of heads in that line, rounded to the nearest whole number. If this percentage is 50% or greater, you should print a "You win!" message; otherwise, print "You lose!". For example, consider the following input file: H T H H T Tails taIlS tAILs TailS heads HEAds hEadS For the input above, your method should produce the following output: 6 heads (50%) You win!
Answer:
Here is the JAVA program:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException{ //the start of main() function body, it throws an exception that indicates a failed attempt to open the file
Scanner input = new Scanner(new File("file.txt")); //creates a Scanner object and a File object to open and scan through the file.txt
coinFlip(input); } //calls coinFlip method
public static void coinFlip(Scanner input) { //coinFlip method that accepts as its parameter a string input holding a file name
while(input.hasNextLine()) { //iterates through the input file checking if there is another line in the input file
Scanner scan = new Scanner(input.nextLine()); //creates a Scanner object
int head = 0; // stores count of number of heads
int count = 0; //stores count of total number of tokens
while(scan.hasNext()) { //iterates through the sequence checking if there is another sequence in the input file
String token= scan.next(); // checks and returns the next token
if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads")) { //compares H or Heads with the tokens in file ignoring lower case and upper case differences
head++; } //if a token i.e. any form of heads in file matches with the H or Heads then add 1 to the number of heads
count++; } //increment to 1 to compute total number of counts
double result = Percentage(head, count); //calls Percentage method passing number of heads and total counts to compute the percentage of heads
System.out.println(head + " heads " + "(" + result +"%)"); // prints the number of heads
if(result >= 50.00) { //if the percentage is greater or equal to 50
System.out.println("You win!");} //displays this message if above if condition is true
else //if the percentage is less than 50
{System.out.println("You lose!");} } } //displays this message if above if condition is false
public static double Percentage(int h, int total) { //method to compute the percentage of heads
double p = (double)h/total* 100; // divide number of heads with the total count and multiply the result by 100 to compute percentage
return p; } } //returns result
Explanation:
The program is well explained in the comments mentioned with each line of the above code. I will explain how the method coinFlip works.
Method coinFlip accepts a string holding a file name as its parameter. It opens that file and reads its contents as a sequence of tokens. Then it reads and scans through each token and the if condition statement:
if (token.equalsIgnoreCase("H")||token.equalsIgnoreCase("Heads"))
checks if the each token in the sequence stored in the file is equal to the H or Heads regardless of the case of the token. For example if the first token in the sequence is H then this if condition evaluates to true. Then the head++ statement increments the count of head by 1. After scanning each token in the sequence the variable count is also increased to 1.
If the token of the sequence is HeAds then this if condition evaluates to true because the lower or upper case difference is ignored due to equalsIgnoreCase method. Each time a head is found in the sequence the variable head is incremented to 1.
However if the token in the sequence is Tails then this if condition evaluates to false. Then the value of head variable is not incremented to 1. Next the count variable is incremented to 1 because this variable value is always incremented to 1 each time a token is scanned because count returns the total number of tokens and head returns total number of heads in the tokens.
Percentage method is used to return the percentage of the number of heads in the sequence. It takes head and count as parameters (h and total). Computes the percentage by this formula h/total* 100. If the result of this is greater than or equal to 50 then the message You win is displayed otherwise message You lose! is displayed in output.
The penalties for ignoring the requirements for protecting classified information when using social networking services are _________________ when using other media and methods of dissemination.
The penalties for ignoring the requirements for protecting classified information when using social networking services are the same when using other media and methods of dissemination.
The penalties are the same because it does not matter what the medium used, the effect is that classified information and confidential details have been left unguarded and exposed.
When in hold of such information, it is not okay to leave it unguarded or exposed. A person who is found guilty of disclosure of classified materials would face sanctions such as:
They would be given criminal sanctionsThey would face administrative sanctionsThey would also face civil litigationsRead more on https://brainly.com/question/17207229?referrer=searchResults
how do you run a function in python?
Given a number N, write a code to print all psoitive numbers less than N in which all adjacent digits differ by 1
Answer:
def lesser_adjacent_num ( N ):
N = int( N )
while N == True:
next = N - 1
print if next >= 0 ? next : break
Explanation:
The python function above called "lesser_adjacent_num" accepts an argument called "N" which is an integer. The function print the number "next" which is a number less than the N integer for every loop for the condition where N is not zero.
Bar-code readers are typically used to track large numbers of inventory items, as in grocery store inventory and checkout, package tracking, warehouse inventory control, and zip code routing for postal mail.
A. True
B. False
What do Quadratic Selection sort, and Shell sort have in common?
They both used a/an_______based implementation in the standard form and are both relatively_____to the order of the data. The main similarity is that each one creates an environment in which a_____strategy works more efficiently.
1. blank
2. linked list
3. array
4. hybrid
5. tree
6. sensitive
7. insensitive
8. complex
9. modern
10. simple
11. retrograde
12. advanced
Answer:
a) An ARRAY ( 3 )
B) relatively INSENSITIVE ( 7 )
c) a HYBRID ( 4 )
Explanation:
They both used an array based implementation in the standard form and are both relatively insensitive to the order of the data. The main similarity is that each one creates an environment in which a hybrid strategy works more efficiently.
Quadratic selection sort is the sorting system that sorts out the smallest value in an entire list and arrange the list in such a way that the smallest value comes first.
b. Does “refactoring” mean that you modify the entire design iteratively? If not, what does it mean?
Explanation:
Refactoring consists of improving the internal structure of an existing program's source code, while preserving its external behavior.
Describe how asymmetric encryption is used to send a message from User A to User B that assures data confidentiality, authentication, and integrity. Be specific as to the keys used and how they achieve the three goals.
Answer:
Find the explanation below.
Explanation:
Asymmetric encryption is a system of communication in technology between two parties where keys which are variable values coined by an algorithm are used to encrypt and decrypt the messages between the sender and receiver. The two types of keys used in this process are the public and private keys. The public keys can be used by anyone to encrypt messages which are then sent to the receiver who decrypts the message using his private keys. The private keys on the other hand are only shared by the person who first set up the key. In sending messages this way, the receiver's public key is gotten from a public directory, and the message encrypted by the sender. The receiver can then decrypt the message using his private keys. But if the message is encrypted using a private key, it is decrypted by the receiver with a public key.
The one-way nature of this style of communication ensures data integrity and confidentiality since users are not required to disclose their keys and only the two parties can access the message. The two end users also preserve the right to authenticate the keys. The transport layer security protocol makes use of asymmetric encryption.
Suppose that the tuition for a university is $10,000 this year and increases 4% every year. In one year, the tuition will be $10,400. Write a program using for loop that computes the tuition in ten years and the total cost of four years’ worth of tuition after the tenth year.
Answer:
The programming language is not stated; however, I'll answer using Python programming language (See attachment for proper format)
tuition = 10000
rate = 0.04
for i in range(1,15):
tuition = tuition + tuition * rate
if i <= 10:
print("Year "+str(i)+" tuition:",end=" ")
print(round(tuition,2))
if i == 14:
print("Tuition 4th year after:",end=" ")
print(round(tuition,2))
Explanation:
The first 2 lines initializes tuition and rate to 10000 and 0.04 respectively
tuition = 10000
rate = 0.04
The next line iterates from year 1 to year 14
for i in range(1,15):
This line calculates the tuition for each year
tuition = tuition + tuition * rate
The next 3 lines prints the tuition for year 1 to year 10
if i <= 10:
print("Year "+str(i)+" tuition:",end=" ")
print(round(tuition,2))
The next 3 lines prints the tuition at the 4th year after year 10 (i.e. year 14)
if i == 14:
print("Tuition 4th year after:",end=" ")
print(round(tuition,2))
a_____________ may have its value change during program execution. options. flowchart,counter, Algorithm,None of them
Answer:
i think is "none of them"
EAPOL operates at the network layers and makes use of an IEEE 802 LAN, such as Ethernet or Wi-Fi, at the link level.
A. True
B. False
Scams where people receive fraudulent emails that ask them to supply account information are called ________.
Answer:
"Phishing" will be the correct approach.
Explanation:
This aspect of cyber attacks or fraud is called phishing, whereby clients or users are questioned for personally identifiable information about them.Attackers could very well-currently the most frequently use phishing emails to exchange malicious programs that could operate effectively in what seems like several different ways. Others would get victims to steal user credentials including payment details.
Your car must have two red stoplights, seen from ______ feet in the daytime, that must come on when the foot brake is pressed.
A. 100
B. 200
C. 300
D. 400
Answer:
the answer is 300 feet in the daytime
Q2) Answer the following:
1- Expression d=i++; causes:
a. The value of i incremented by 1
b- The value of i assigned to d
C- The value of i assigned to d then i incremented by 1
d- The value ol i incremented by 1 then assigned to d.
CO
SA
Answer:
D
Explanation:
The value of i is incremented by one then assigned to d
The Adjacent Coins Problem Published on 2017-08-30 Consider N coins aligned in a row. Each coin is showing either heads or tails. The adjacency of these coins is the number of adjacent pairs of coins with the same side facing up. Write a program that given a non-empty zero-indexed array A consisting of N integers representing the coins, returns the maximum possible adjacency that can be obtained by reversing exactly one coin (that is, one of the coins must be reversed). Consecutive elements of array A represent consecutive coins in the row. Array A contains only 0s and/or 1s:
Answer:
Here is the JAVA code:
public class Main{
public static int solution(int[] A) { //method that takes non-empty array A consisting of 0s and 1s
int N = A.length; // number of 0s and 1s in array A
int r = 0; //result of adjacency
for (int i = 0; i < N - 1; i++; ) { // iterates through A
if (A[i] == A[i + 1]) //if i-th element of A is equal to (i+1)th element
r = r + 1; } //add 1 to the count of r
if (r == N-1) //for test cases like {1,1}
{return r-1; }
int max = 0; //to store maximum possible adjacency
for (int i = 0; i <N; i++) { //iterates through array
int c = 0;
if (i > 0) { //starts from 1 and covering the last
if (A[i-1] != A[i]) //checks if i-1 element of A is not equal to ith element of A
c = c + 1; //adds 1 to counter variable
else
c = c - 1; } //decrements c by 1
if (i < N - 1) {//starting with 0
if (A[i] != A[i + 1]) //checks if ith element of A is not equal to i+1th element of A
c = c + 1; //adds 1 to counter variable
else
c = c - 1; } //decrements c by 1
max = Math.max(max,c); } //finds the maximum of max and c
return r + max; } //returns result + maximum result
public static void main(String[] args) {
int[] A = {1, 1, 0, 1, 0, 0}; //sample array to test the method
System.out.println(solution(A));} } //calls the method passing array to it
Explanation:
The program works as follows:
A[] = {1, 1, 0, 1, 0, 0}
N = A.length
N = 6
The A has the following elements:
A[0] = 1
A[1] = 1
A[2] = 0
A[3] = 1
A[4] = 0
A[5] = 0
Program iterates through array A using for loop. Loop variable i is initialized to 0
if condition if (A[i] == A[i + 1]) checks
if (A[0] == A[0 + 1])
A[0] = 1
A[0 + 1] = A[1] = 1
They both are 1 so they are equal
r = r + 1;
Since the above if condition is true so 1 is added to the value of r Hence
r = 1
At each iteration of the loop the if condition checks whether the adjacent elements of A are equal. If true then r is incremented to 1 otherwise not.
So after all the iterations value of r = 2
if (r == N-1) evaluates to false because r=2 and N-1 = 5
So program moves to the statement:
for (int i = 0; i <N; i++)
This loop iterates through the array A
if (i > 0) condition checks if value of i is greater than 0. This evaluates to false and program control moves to statement:
if (i < N - 1) which makes if(0<5) This evaluates to true and program control moves to statement
if (A[i] != A[i + 1]) which means:
if (A[0] != A[0 + 1]) -> if (A[0] != A[1])
We know that
A[0] = 1
A[1] = 1
So this evaluates to false and else part is executed:
value of c is decremented to 1. So c=-1
max = Math.max(max,c) statement returns the max of max and c
max = 0
c = -1
So max = 0
value of i is incremented to 1 so i = 1
At next step:
if (i < N - 1) which makes if(1<5) This evaluates to true and program control moves to statement
if (A[i] != A[i + 1]) which means:
if (A[1] != A[1 + 1]) -> if (A[1] != A[2])
A[1] = 1
A[2] = 0
So the statement evaluates to true and following statement is executed
c = c + 1; The value of c is incremented to 1. So
c = -1 + 1
Hence
Hence c= 0, max = 0 and i = 2
next step:
if (i < N - 1) which makes if(2<5) This evaluates to true and program control moves to statement
if (A[i] != A[i + 1]) which means:
if (A[2] != A[2 + 1]) -> if (A[2] != A[3])
A[2] = 0
A[3] = 1
So the statement evaluates to true and following statement is executed
c = c + 1; The value of c is incremented to 1. So
c = 0 + 1
c = 1
Hence
The statement max = Math.max(max,c) returns the max of max and c
max = 0
c = 1
So max = 1
Hence c= 1, max = 1 and i = 3
next step:
if (i < N - 1) which makes if(3<5) This evaluates to true and program control moves to statement
if (A[i] != A[i + 1]) which means:
if (A[3] != A[3 + 1]) -> if (A[3] != A[4])
A[3] = 1
A[4] = 0
So the statement evaluates to true and following statement is executed
c = c + 1; The value of c is incremented to 1. So
c = 1 + 1
c = 2
Hence
The statement max = Math.max(max,c) returns the max of max and c
max = 1
c = 2
So max = 2
Hence c= 2, max = 2 i = 4
next step:
if (i < N - 1) which makes if(4<5) This evaluates to true and program control moves to statement
if (A[i] != A[i + 1]) which means:
if (A[4] != A[4+ 1]) -> if (A[4] != A[5])
A[4] = 0
A[5] = 0
So this evaluates to false and else part is executed:
value of c is decremented to 1. So c=1
max = Math.max(max,c) statement returns the max of max and c
max = 2
c = 1
So max = 2
value of i is incremented to 1 so i = 5
next step:
if (i < N - 1) which makes if(5<5) This evaluates to false
if (i > 0) evaluates to true so following statement executes:
if (A[i-1] != A[i])
if (A[5-1] != A[5])
if (A[4] != A[5])
A[4] = 0
A[5] = 0
This statement evaluates to false so else part executes and value of c is decremented to 1
Hence
max = 2
c = 0
So max = 2
value of i is incremented to 1 so i = 6
The loop breaks because i <N evaluates to false.
Program control moves to the statement:
return r + max;
r = 2
max = 2
r + max = 2+2 = 4
So the output of the above program is:
4
An organization is building a new customer services team, and the manager needs to keep the team focused on customer issues and minimize distractions. The users have a specific set of tools installed, which they must use to perform their duties. Other tools are not permitted for compliance and tracking purposes. Team members have access to the Internet for product lookups and to research customer issues. Which of the following should a security engineer employ to fulfill the requirements for the manager?a. Install a web application firewallb. Install HIPS on the team's workstations.c. implement containerization on the workstationsd. Configure whitelisting for the team
Answer:
a
Explanation:
because they need to protect the organization's information
What is resource management in Wireless Communication? Explain its advantages
Answer:
Wireless resources management is communication to address they faster response time.
Explanation:
Wireless communication that provide bandwidth, and transmission reliable, towards development.
This communication is discovered to the date and have consumed physical layer of available wireless resources.
Wireless communication management all this critical topic and the management techniques, and limited device battery power.
Communication as the address channel loss, and multi path .
Communication are the latest resources allocation and new or next generation and technologies.
Wireless communication theoretical concepts in a manner, and the necessary mathematical tools and fundamental tools.
Wireless communication device industries up to date of the topic,readers are benefit from a basic.
Write the program to compute how many gallons of paint are needed to cover the given square feet of walls. Assume 1 gallon can cover 350.0 square feet. So gallons =the square feet divided by 350.0. If the input is 250.0, the output should be: 0.714285714286
Answer:
Here is the Python and C++ program.
Python program:
gallons_paint=0.0 #declare and initialize gallons_paint
wall_area = float(input()) #prompts user to enter wall area
gallons_paint = wall_area / 350 #formula to compute gallons of paint needed to cover the given square feet of walls
print(gallons_paint) #display the result
C++ program:
#include <iostream> //to use input output functions
using namespace std; //to identify objects like cin cout
int main(){ //start of main() function body
float wall_area,gallons_paint=0; //declare variables
cin>>wall_area; //reads input wall area from user
gallons_paint=wall_area/350; //formula to compute gallons of paint needed to cover the given square feet of walls
cout<<gallons_paint;} //print the result
Explanation:
The program prompts the user to enter the area of wall and stores the input value in wall_area
Suppose the user enters 250 as wall area
The the formula gallons_paint=wall_area/350; works as follows:
gallons_paint = wall_area/350;
= 250/350
= 0.71428
gallons_paint = 0.71428
So the output is:
0.71428
The screenshot of the program along with its output is attached.
Bharath has made a table of content for his document in Open Office, in which he wants to make few changes, but he is unable to make the changes. Give reason. Explain how he can make the necessary changes
Answer:
H cannot update it because it is probably protected.
If you cannot click in the table of contents, it is probably because it is protected. To disable this protection, choose Tools > Options > OpenOffice.org Writer > Formatting Aids, and then select Enable in the Cursor in protected areas section. If you wish to edit the table of contents without enabling the cursor, you can access it from the Navigator.
Explanation:
. To update a table of contents when changes are made to the document:
Right-click anywhere in the TOC.
From the pop-up menu, choose Update Index/Table. Writer updates the table of contents to reflect the changes in the document.
You can also update the index from the Navigator by right-clicking on Indexes > Table of Contents1 and choosing Index > Update from the pop-up menu.
Giving Brainliest IFFF CORRECT
Jonathan needs to create a chart that shows the change in weight he can lift in weightlifting class. Which chart or graph should he use?
Bar graph
Column chart
Line graph
Pie chart
Answer:
line graph
Explanation:
the change in weight is linear
Answer:
Line Graph
Explanation:
Linear Weight change
The breastbone or ________________ extends down the chest.
Answer:
The sternum or breastbone is a long flat bone located in the central part of the chest.
The sternum or breastbone is a long flat bone located in the central part of the chest.
In the middle of the chest, there is a long, flat bone known as the sternum or breastbone. It forms the front of the rib cage and is joined to the ribs by cartilage, assisting in the protection of the heart, lungs, and major blood arteries from harm. It is one of the longest and largest flat bones in the body, somewhat resembling a necktie. The manubrium, body, and xiphoid process are its three regions.
Therefore, the sternum or breastbone is a long flat bone located in the central part of the chest.
Learn more about the breastbone here:
https://brainly.com/question/32917871.
#SPJ2
PROGRAM 8: Grade Converter! For this program, I would like you to create a function which returns a character value based on a floating point value as
Answer:
This function will return a character grade for every floating-point grade for every student in the class.
function grade( floatPoint ){
let text;
switch ( floatPoint ) {
case floatPoint < 40.0 :
text= " F ";
break;
case floatPoint == 40.0 :
text= " P ";
break;
case floatPoint > 40.0 && floatPoint <= 50.0 :
text= " C ";
break;
case floatPoint > 50.0 && floatPoint < 70.0 :
text= " B ";
break;
case floatPoint >=70.0 && floatPoint <= 100.0 :
text= " C ";
break;
default :
text= "Floating point must be between 0.0 to 100.0"
}
return text;
}
Explanation:
This javascript function would return a character grade for floating-point numbers within the range of 0.0 to 100.0.
a) Code a statement that creates an instance of an Account class using the default constructor and stores the object that’s created in a variable named account.
b) Code a statement that creates an instance of the Account class using a constructor that has two parameters named firstName and age, and store the object in a variable named account. Assume that variables with those names have already been declared and initialized so you can pass those variables to the constructor.
c) Code a statement that sets the value of the Age property of an Account object named account to the value in a variable named newAge.
d) Code a statement that will get the value of a public static field named Count that’s defined in the Account class, and store the value in a new int variable named count. Assume that you’ve already created an object from this class that’s named account.
Answer:
a)
Account account = new Account();
b)
Account account = new Account(firstName, age);
c)
account.Age = newAge;
d)
int count = Account.Count;
Explanation:
a)
new is the keyword which is used to create an object.
Account is the class name.
account is the name of an object of class Account.
account object is created to access the class Account.
Account() is the constructor of Account class. This is the default constructor and it has no parameters. Constructor has the same name as class. When a account object is created, constructor Account will be invoked.
b)
Account is the class name.
account is the name of an object of class Account.
Account() is the constructor of Account class. This is the parameterized constructor and it has two parameters i.e. firstName and age. Constructor has the same name as class. When a account object is created, constructor Account will be invoked.
c)
account.Age = newAge;
Here account is the object name. The Age property to access and update the private field of the Account class is set to the variable named newAge.
d)
This int count = Account.Count; statement gets the value of a public static field named Count that’s defined in the Account class, and stores the value in a new int variable named count.
Ann. An employee in the payroll department, has contacted the help desk citing multiple issues with her device, including: Slow performance Word documents, PDFs, and images no longer opening A pop-up Ann states the issues began after she opened an invoice that a vendor emailed to her. Upon opening the invoice, she had to click several security warnings to view it in her word processor. With which of the following is the device MOST likely infected?
a. Spyware
b. Crypto-malware
c. Rootkit
d. Backdoor
Answer:
d. Backdoor
Explanation:
A backdoor is a type of malware that overrides security checks and authentications to access a computer or embedded device.
When this is done, remote access is granted and databases and servers can be accessed and modified. Attackers can also give remote commands to the system.
What happened to Ann in the payroll department is probably a backdoor attack that affected her device.
Write a script named dif.py. This script should prompt the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the script should simply output "Yes". If they are not, the script should output "No", followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file, including whitespace and punctuation. The loop should break as soon as a pair of different lines is found.
Answer:
Following are the code to this question:
f1=input('Input first file name: ')#defining f1 variable that input file 1
f2=input('Input second file name: ')#defining f2 variable that input file 2
file1=open(f1,'r')#defining file1 variable that opens first files by using open method
file2=open(f2,'r')#defining file1 variable that opens second files by using open method
d1=file1.readlines()#defining d1 variable that use readlines method to read first file data
d2=file2.readlines()#defining d2 variable that use readlines method to read second file data
if d1==d2:#defining if block that check file data
print('Yes')#when value is matched it will print message yes
exit# use exit keyword for exit from if block
for j in range(0,min(len(d1),len(d2))):#defining for loop that stores the length of the file
if (d1[j]!=d2[j]):#defining if block that check value is not matched
print('No')#print the message "NO"
print("mismatch values: ",d1[j]," ",d2[j])#print file values
Output:
please find the attached file.
Explanation:
code description:
In the above code, the "f1 and f2" variable is used for input value from the user end, in which it stores the file names. In the next step, the "file1 and file2" variable is declared that uses the open method to open the file. In the next line, the"d1 and d2" variable is declared for reads file by using the "readlines" method. Then, if block is used that uses the "d1 and d2" variable to match the file value if it matches it will print "yes", otherwise a for loop is declared, that prints files mismatch values.Answer:
first = input("enter first file name: ")
second = input("enter second file name: ")
file_one = open(first, 'r')
file_two = open(second, 'r')
if file_one.read() == file_two.read():
print("Both files are the same")
else:
print("Different files")
file_one.close()
file_two.close()
list three components of a computer system
11. Which of the following is word processing
software?
Hope this is correct
HAVE A GOOD DAY!
Define Proportional spacing fornt.
Answer:
Alphabetic character spacing based on the width of each letter in a font. ... Proportional spacing is commonly used for almost all text. In this encyclopedia, the default text is a proportional typeface, and tables are "monospaced," in which all characters have the same fixed width.
hope this answer helps u
pls mark me as brainlitest .-.
Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented. Implement a Python methods that works like the following: a. count b. in: return True if the item is in the list c. reverse d. index: return -1 if the item is not in the list e. insert
Answer:
Here are the methods:
a) count
def count(object, list):
counter = 0
for i in list:
if i == object:
counter = counter + 1
return counter
b) in : return True if the item is in the list
def include(object, list):
for i in list:
if i == object:
return True
return False
c) reverse
def reverse(list):
first = 0
last = len(list)-1
while first<last:
list[first] , list[last] = list[last] , list[first]
first = first + 1
last = last - 1
return list
d) index: return -1 if the item is not in the list
def index(object, list):
for x in range(len(list)):
if list[x] == object:
return x
return -1
e) insert
def insert(object, index, list):
return list[:index] + [object] + list[index:]
Explanation:
a)
The method count takes object and a list as parameters and returns the number of times that object appears in the list.
counter variable is used to count the number of times object appears in list.
Suppose
list = [1,1,2,1,3,4,4,5,6]
object = 1
The for loop i.e. for i in list iterates through each item in the list
if condition if i == object inside for loop checks if the item of list at i-th position is equal to the object. So for the above example, this condition checks if 1 is present in the list. If this condition evaluates to true then the value of counter is incremented to 1 otherwise the loop keeps iterating through the list searching for the occurrence of object (1) in the list.
After the complete list is moved through, the return counter statement returns the number of times object (i.e. 1 in the example) occurred in the list ( i.e. [1,1,2,1,3,4,4,5,6] ) As 1 appears thrice in the list so the output is 3.
b)
The method include takes two parameters i.e. object and list as parameters and returns True if the object is present in the list otherwise returns False. Here i have not named the function as in because in is a reserved keyword in Python so i used include as method name.
For example if list = [1,2,3,4] and object = 3
for loop for i in list iterates through each item of the list and the if condition if i == object checks if the item at i-th position of the list is equal to the specified object. This means for the above example the loop iterates through each number in the list and checks if the number at i-th position in the list is equal to 3 (object). When this if condition evaluates to true, the method returns True as output otherwise returns False in output ( if 3 is not found in the list). As object 3 is present in the list so the output is True.
c) reverse method takes a list as parameter and returns the list in reverse order.
Suppose list = [1,2,3,4,5,6]
The function has two variables i.e. first that is the first item of the list and last which is the last item of the list. Value of first is initialized to 0 and value of last is initialized to len(list)-1 where len(list) = 6 and 6-1=5 so last=5 for the above example. These are basically used as index variables to point to the first and last items of list.
The while loop executes until the value of first exceeds that of last.
Inside the while loop the statement list[first] , list[last] = list[last] , list[first] interchanges the values of elements of the list which are positioned at first and last. After each interchange the first is incremented to 1 and last is decremented to 1.
For example at first iteration:
first = 0
last = 5
list[0] , list[5] = list[5] , list[0]
This means in the list [1,2,3,4,5,6] The first element 1 is interchanged with last element 6. Then the value of first is incremented and first = 1, last = 4 to point at the elements 2 and 5 of the list and then exchanges them too.
This process goes on until while condition evaluates to false. When the loop breaks statement return list returns the reversed list.
d) The method index takes object and list as parameters and returns the index of the object/item if it is found in the list otherwise returns -1
For example list = [1,2,4,5,6] and object = 3
for loop i.e. for x in range(len(list)): moves through each item of the list until the end of the list is reached. if statement if list[x] == object: checks if the x-th index of the list is equal to the object. If it is true returns the index position of the list where the object is found otherwise returns -1. For the above examples 3 is not in the list so the output is -1
e) insert
The insert function takes as argument the object to be inserted, the index where the object is to be inserted and the list in which the object is to be inserted.
For example list = [0, 1, 2, 4, 5, 6] and object = 3 and index = 3
3 is to be inserted in list [1,2,4,5] at index position 3 of the list. The statement:
return list[:index] + [object] + list[index:]
list[:index] is a sub list that contains items from start to the index position. For above example:
list[:index] = [0, 1, 2]
list[index:] is a sub list that contains items from index position to end of the list.
list[index:] = [4, 5, 6]
[object] = [3]
So above statement becomes:
[0, 1, 2] + [3] + [4, 5, 6]
So the output is:
[0, 1, 2, 3, 4, 5, 6]