Question

In: Computer Science

Can you please write this in python and comment as well so I can understand what...

Can you please write this in python and comment as well so I can understand what yo are doing. Thank you.

1)Loop through list A, at each iteration, show the square root result of that element. Add proper text to your print function.

A = [-4, 1, -16, 36, -49, 64, -128]

2)Create a counter variable, name it i and initialize it to 0. Using a for loop, count how many numbers are divisible by 3 in range of 1 to 50.

3)Consider a string called S. Convert S into a list of words using split method. Then use a for loop to iterate over the list of words, only if letter c is in a word, print it. For example:

if ‘x’ in word: print(word).

S = “This class has three credits”


4) Create a for loop that iterates over list C and only prints an element if it’s a number (int or float).


C = [13, ‘not me’, -4, ‘skip this one’, 6.1, 0.9, ‘NO’]

Solutions

Expert Solution

1)

#list
A = [-1,1,-16,36,-49,64,-128]
# runs the loop on a list
for i in range(len(A)):
# pow(base,power) is a function which calculates the power of given number
# square number is stored in temp varaible
temp = pow(A[i],2)
#prints the squre of a number
print(temp)

2)

#list
A = [-1,1,-16,36,-49,64,-128]
counter = 0
# runs the loop on a list
for i in range(len(A)):
#checks the condition for the number is in range 1 to 50
# and is it divisible by 3 or not when all three conditions are meet then only if block is executed
if(A[i]>1 and A[i]<50 and A[i]%3==0):
#counter increment
counter+=1
#prints the
print(counter)

3)

# string
S = "This class has three credits"
# converting string to list by .split()function
lst = S.split()
# runs the loop on list
for i in range(len(lst)):
# checks the condition character 'c' present in word or not
if 'c' in lst[i]:
#print the word
print(lst[i])

4)

C = [13,'not me',-4,'skip this one',6.1,0.9,'NO']
# runs the loop
for i in range(len(C)):
# checks the condition
if (type(C[i]) == int or type(C[i]) == float):
# print the element
print(C[i])
  

TRY TO TYPE THE CODE FROM GIVEN IMAGES

BEAWARE OF INDENTATION

THUMBS UP


Related Solutions

Please explain to me the answers so that I can understand the concept. Thank you! You...
Please explain to me the answers so that I can understand the concept. Thank you! You must evaluate a proposal to buy a new milling machine. The purchase price of the milling machine, including shipping and installation costs, is $126,000, and the equipment will be fully depreciated at the time of purchase. The machine would be sold after 3 years for $85,000. The machine would require a $3,500 increase in net operating working capital (increased inventory less increased accounts payable)....
(Please show work so I can understand how you got to the answer - Thank you...
(Please show work so I can understand how you got to the answer - Thank you very much ) Via Gelato is a popular neighborhood gelato shop. The company has provided the following data concerning its operations: Fixed Element per Month Variable Element per Liter Actual Total for June Revenue $ 13.00 $ 72,540 Raw materials $ 4.75 $ 30,330 Wages $ 5,700 $ 1.50 $ 14,560 Utilities $ 1,730 $ 0.30 $ 3,800 Rent $ 2,700 $ 2,700 Insurance...
Please show full work so that I can understand these types of problems, thank you! Complete...
Please show full work so that I can understand these types of problems, thank you! Complete the following Complex Time Value of Money problem. You are doing some long-range retirement planning. On the day you retire (23 years from now) you want to be able to withdraw $200,000. Then, you want to withdraw the following amounts at the end of each year after that (during your retirement period).                            Years 1-4            $160,000                            Years 5-9            $175,000                            Years 10-15       $165,000...
Please show work - trying to understand how to do this so I can apply it...
Please show work - trying to understand how to do this so I can apply it to other problems. Both Professor X and Professor Y agree that students who study for their examinations do better than those who do not. Both professors teach the same class, take a careful four level ranking of how hard their students studied and give a very similar examination. This year the average score in Professor X’s class and the average score in Professor Y’s...
Please write the answer in word form so i can copy What is the purpose of...
Please write the answer in word form so i can copy What is the purpose of saying “all-else-equal” or “ceteris paribus” when it comes to multiple linear regression? Why is the F-test important in multiple linear regression more so than in simple linear regression? What is the difference between the AIC and BIC? Why is outlier analysis so important? What is the danger in using stepwise regression? What is the difference between Cook’s Distance and DFFITS? What can you do...
Can you write this program, but in python, I just wanna see what am I doing...
Can you write this program, but in python, I just wanna see what am I doing wrong. thank you Instructions: The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $10.00 or more and $3.00 otherwise. Three kinds of gasoline are available: regular at $2.89, plus at $3.09, and super at $3.39 per gallon. User Request: Write a program that prints a statement for a customer. Analysis:...
please can you write the calc_plant method in another way, I don't understand way they assign...
please can you write the calc_plant method in another way, I don't understand way they assign these specific numbers to min, unhappy1...4. the question says if the plant is within two miles or less of a city, the unhappiness is infinite (that is, assign a very large number to the unhappiness for that city). 2) Otherwise, the unhappiness is equal to the population of the city divided by the distance of the plant from the city. The average unhappiness equals:...
PLEASE USE FORMULA AND NOT EXCEL SO I CAN UNDERSTAND HOW TO USE FORMULA THE INITIAL...
PLEASE USE FORMULA AND NOT EXCEL SO I CAN UNDERSTAND HOW TO USE FORMULA THE INITIAL QUESTION: Gerald has taken out a loan of $100,000 today to start a business. He has agreed to repay the loan on the following terms: Repayments will be made on a monthly basis. The first repayment will be made exactly one month from today. The repayments for the first 5 years will cover interest only to help reduce the financial burden for Gerald’s business...
Please post all the work so I can understand the process! Thanks :) Question 3: The...
Please post all the work so I can understand the process! Thanks :) Question 3: The 9-month salaries at a daycare center are normally distributed with a mean of $18,000 and a standard deviation of $5,000. a. What is the probability that an employee will have a salary between $15,520 and $18,480? b. What is the probability that an employee will have a salary more than $19,880? c. What is the probability that an employee will have a salary less...
​​​​​​​Please post the work so I can understand the process :) Thanks! Telephone calls arrive at...
​​​​​​​Please post the work so I can understand the process :) Thanks! Telephone calls arrive at the Global Airline reservation office in Louisville according to a Poisson distribution with a mean of 1.6 calls per minute: a. What is the probability of receiving exactly one call during a one-minute interval? b. What is the probability of receiving at most 2 calls during a one-minute interval? c. What is the probability of receiving at least two calls during a one-minute interval?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT