answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IrinaK
2 months ago
7

Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to

be a list or tuple of numbers. This function should return a new list, which contains the square of each value in collection. To do so, inside the function, you will define a new list, use a loop to loop through the input list, use an operator to square the current value, and use the append method to add this to your output list. After the loop, return the output list.g
Computers and Technology
1 answer:
zubka84 [1K]2 months ago
4 0
Refer to the explanation Define the function square_all() that receives a list of integers. This function should return a new list containing the square values of all integers found within the provided list. def square_all(num_list): #Initiate an empty list to store results. sq_list = [] #Iterate through the length of the list. for index in range(0, len(num_list)): #Calculate the square of the current value and add it to the result list sq_list. sq_list.append(num_list[index] * num_list[index]) #Return the squared values of all integers in num_list. return sq_list #Declare and initialize a list of integers. intList = [2, 4] #Invoke the square_all() function and pass the above list as an argument. Show the returned list. print(square_all(intList))
You might be interested in
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Els
Natasha_Volkova [1026]
Here's a C code snippet: #include <stdio.h> int main() { int year; printf("enter year:"); scanf("%d",&year); if(year>=2101) { printf("Distant future"); } else if(year>=2001&&year<=2100) { printf("21st century"); } else if(year>=1901&&year<=2000) { printf("20th century"); } else if(year<=1900) { printf("Long ago"); } return 0;} Output: enter year:2018 21st century. </stdio.h>
7 0
1 month ago
Read 2 more answers
Write a generator function named count_seq that doesn't take any parameters and generates a sequence that starts like this: 2, 1
zubka84 [1067]

Response:

#code (count_seq.py)

def count_seq():

   n='2'

   while True:

       yield int(n)

       next_value=''

       while len(n)>0:

           first=n[0]

           count=0

     

           while len(n)>0 and n[0]==first:

               count+=1

               n=n[1:]

           next_value+='{}{}'.format(count,first)

       n=next_value

if __name__ == '__main__':

   gen=count_seq()

   for i in range(10):

       print(next(gen))

Clarification:

  • Begin with the number 2. Utilize a string for easier manipulation rather than integers.
  • Engage in an infinite loop.
  • Yield the current integer value of n.
  • Continue looping until n becomes an empty string.
  • Repeat as long as n has content and the first digit matches the leading digit.
  • Concatenate the count and the first digit to form next_value.
3 0
1 month ago
Represent decimal number 8620 in (a) BCD, (b) excess-3 code, (c)2421 code, and (d) as a binary number
maria [1035]

The decimal number 8620 can be expressed in the following ways:

a = 1000 0110 0010 0000

b = 1011 1001 0101 0011

c = 1110 1100 0010 0000

d = 10000110101100

I hope these representations answer your question and prove useful.

4 0
3 months ago
To what extent are the following computer systems instances of artificial intelligence:
oksian1 [950]

Answer: Scanners used in supermarkets for barcodes and voice-activated phone menus are not examples of artificial intelligence.

Explanation:

(a) Supermarket barcode scanners can read codes, yet they lack the capability to employ machine learning techniques for learning patterns within the codes. Machine learning is a crucial aspect of artificial intelligence (AI), thus indicating they do not qualify as instances of AI. Likewise, voice-activated menus can only present options and do not carry out any complex tasks.

In contrast, web search engines and internet routing algorithms demonstrate dynamic and intelligent capabilities in processing and delivering information to users.

Hence, these are considered examples of AI.

8 0
3 months ago
Access-lists pose a logical problem which often has more than one solution. Can you think of a different set of rules or placeme
maria [1035]
The question is incomplete, as it lacks a diagram of the topology and Router R1's table. I assume the user has access to both the topology and routing information. The configuration below will assist in resolving the ACL issue: Hosts within the 172.16.0.0/16 network should have unrestricted access to Server1, Server2, and Server3, which is currently not the case since L1 is unable to connect to Server2 or Server3. The suggested configuration on Cisco Router R1 will rectify the ACL issues.
6 0
1 month ago
Other questions:
  • Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
    13·2 answers
  • The part of the computer that contains the brain, or central processing unit, is also known as the A.monitor B.modem C.keyboard
    10·1 answer
  • Charlie has a large book collection. He was keeping track of it in a spreadsheet, but it has grown big enough that he wants to c
    10·1 answer
  • Assume that getPlayer2Move works as specified, regardless of what you wrote in part (a) . You must use getPlayer1Move and getPla
    14·1 answer
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • Define a method calcPyramidVolume with double data type parameters baseLength, baseWidth, and pyramidHeight, that returns as a d
    8·1 answer
  • Write a loop to populate the list user_guesses with a number of guesses. The variable num_guesses is the number of guesses the u
    13·1 answer
  • An administrator has been working within an organization for over 10 years. He has moved between different IT divisions within t
    8·1 answer
  • HELP ME ON THIS PLEASE ILL GIVE BRAINLY!!!! If U GET IT RIGHT !!!
    10·1 answer
  • Write a statement that defines an ifstream object named inputFile and opens a file named "Friends.txt".
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!