Answer:
Python Code:
def validate_url(url):
#Creating the list of valid protocols and file name extensions
valid_protocols = ['http', 'https', 'ftp']
valid_fileinfo = ['.html', '.csv', '.docx']
#splitting the url into two parts
url_split = url.split('://')
isProtocolValid = False
isFileValid = False
#iterating over the valid protocols and file names for validity
for x in valid_protocols:
if x in url_split[0]:
isProtocolValid = True
break
for x in valid_fileinfo:
if x in url_split[1]:
isFileValid = True
break
#Returning the result if the URL has both valid protocol and file extension
return (isProtocolValid and isFileValid)
url = input("Enter an URL: ")
print(validate_url(url))
Explanation:
The image of the output code is attached. Hope it helps.
Answer:
A. A quiet room
Explanation:
Because if you open the windows the will be noise
a huge room will echoe
a room with air conditioning will make noise
Answer:
C++.
Explanation:
<em>Code snippet.</em>
#include <map>
#include <iterator>
cin<<N;
cout<<endl;
/////////////////////////////////////////////////
map<string, string> contacts;
string name, number;
for (int i = 0; i < N; i++) {
cin<<name;
cin<<number;
cout<<endl;
contacts.insert(pair<string, string> (name, number));
}
/////////////////////////////////////////////////////////////////////
map<string, string>::iterator it = contacts.begin();
while (it != contacts.end()) {
name= it->first;
number = it->second;
cout<<word<<" : "<< count<<endl;
it++;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
I have used a C++ data structure or collection called Maps for the solution to the question.
Maps is part of STL in C++. It stores key value pairs as an element. And is perfect for the task at hand.
Answer:
Let's convert the decimals into signed 8-bit binary numbers.
As we need to find the 8-bit magnitude, so write the powers at each bit.
<u>Sign -bit</u> <u>64</u> <u>32</u> <u>16</u> <u>8</u> <u>4</u> <u>2</u> <u>1</u>
+25 - 0 0 0 1 1 0 0 1
+120- 0 1 1 1 1 0 0 0
+82 - 0 1 0 1 0 0 1 0
-42 - 1 0 1 0 1 0 1 0
-111 - 1 1 1 0 1 1 1 1
One’s Complements:
+25 (00011001) – 11100110
+120(01111000) - 10000111
+82(01010010) - 10101101
-42(10101010) - 01010101
-111(11101111)- 00010000
Two’s Complements:
+25 (00011001) – 11100110+1 = 11100111
+120(01111000) – 10000111+1 = 10001000
+82(01010010) – 10101101+1= 10101110
-42(10101010) – 01010101+1= 01010110
-111(11101111)- 00010000+1= 00010001
Explanation:
To find the 8-bit signed magnitude follow this process:
For +120
- put 0 at Sign-bit as there is plus sign before 120.
- Put 1 at the largest power of 2 near to 120 and less than 120, so put 1 at 64.
- Subtract 64 from 120, i.e. 120-64 = 56.
- Then put 1 at 32, as it is the nearest power of 2 of 56. Then 56-32=24.
- Then put 1 at 16 and 24-16 = 8.
- Now put 1 at 8. 8-8 = 0, so put 0 at all rest places.
To find one’s complement of a number 00011001, find 11111111 – 00011001 or put 0 in place each 1 and 1 in place of each 0., i.e., 11100110.
Now to find Two’s complement of a number, just do binary addition of the number with 1.
Answer:
Following are the code in the Java Programming Language:
try{ //try block.
processor.process(); //
call the function through the object.
}
catch(Exception e){ //catch block .
System.out.println( "process failure"); //if any exception occurs then print.
}
Explanation:
In the following code, we set two blocks in Java Programming Language of the exception handling which is try block or catch block.
- In try block we call the function "process()" through the "processor" object.
- If any exception occurs in the program then the catch block print the following message is "process failure"