logo

Crowdly

Browser

Add to Chrome

Programming for Engineers -Summer25

Looking for Programming for Engineers -Summer25 test answers and solutions? Browse our comprehensive collection of verified answers for Programming for Engineers -Summer25 at elearn.squ.edu.om.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

Write a Python program that reads a text file. The program should:

  1. Extract all words and convert them to lowercase.

  2. Store the words in a list.

  3. Use a dictionary to group the words by their first letter.

  4. Print the letter(s) and the associated words that correspond to the largest number of words

Example of the text file:

Artificial intelligence and algorithms are advancing quickly.

Analytics and automation are at the heart of digital transformation.

Deep learning, data, and design drive development.

Example of code execution:

Enter the filename: quiz2.txt

The letter(s) that correspond to the largest number of words (11):

a: analytics, advancing, at, are, and, artificial, algorithms, automation

View this question
Recursive functions are frequently used to design algorithms for computing values that have a recursive definition.
0%
0%
View this question

Define and test a function myRange. This function should behave like Python’s standard range function, with the required and optional arguments, but it should return a list. Do not use the range function in your implementation! (Hints: Study Python’s help on range to determine the names, positions, and what to do with your function’s parameters. Use a default value of None for the two optional parameters. If these parameters both equal None, then the function has been called with just the stop value. If just the third parameter equals None, then the function has been called with a start value as well. Thus, the first part of the function’s code establishes what the values of the parameters are or should be. The rest of the code uses those values to build a list by counting up or down.)

Test your code with the following examples and ensure you get the same results:

print(myRange(5))          

 [0, 1, 2, 3, 4]

print(myRange(2, 5))      

[2, 3, 4]

print(myRange(2, 10, 3)) 

[2, 5, 8]

print(myRange(5, 2, -1))   

 [5, 4, 3]

print(myRange(5, 2, 1))    

[]

View this question

Write a function rmsFunction(data,t), where data is a list of strings numbers, and t is a threshold. In the function, you should do the following

1) Map the data to floats.

2) Filter to keep only the  values that are greater than or equal to the threshold t. The threshold is set to 0 if not provided by the user.  If no values pass the filter, return None. 

3) Reduce the filtered numbers to compute the root-mean-square (RMS):

Test your code with the following examples:

data = ["3.5", "-2", "0", "4.0", "1.2", "5.3", "-0.7", "2.8"]

#Test 1

t = 2

print(rmsFunction(data,t))

4.0056210504739465

#Test 2

print(rmsFunction(data))

3.307063148273203

#Test 3

t = 10

print(rmsFunction(data,t))

None

View this question

Write a script that has

1)  a function sinEstimate(x,N) that estimates the sin of x using the equation below. If N is not provided, then set it be default to 10. 

2) a  main() function to calculate the error between sinEstimate(x,N) and the build sin(x) from the math module. 

Examples (in the main() function):

# Example 1

print("The absolute error of estimating sinEstimate(pi) is:", abs(sinEstimate(pi)-sin(pi)))

The absolute error of estimating sinEstimate(pi) is: 1.0348063438373582e-11

# Example 2

 print("The absolute error of estimating sinEstimate(pi,5) is:", abs(sinEstimate(pi,5)-sin(pi)))

The absolute error of estimating sinEstimate(pi,5) is: 0.00044516023820933523

View this question

Consider the following code segment:

submissions = [7, 9, 5, 10, 8]

print(submissions[2])

What is displayed when it runs?

0%
0%
0%
0%
View this question

What code completes this code snippet to swap the first and

last element in the list?

states = ["Alaska", "Hawaii", "Florida", "Maine"]
i = 0
________________________
temp = states[j]
states[j] = states[0]
states[i] = temp
0%
0%
0%
0%
View this question

A teacher stores students' grades in a dictionary:

grades = {"Alice": 85, "Bob": 92, "Charlie": 78}

grades["Diana"] = 88

print(len(grades))

What is the output when this code is executed?

View this question
Two teams submitted their project results in the form of ordered scores. The instructor wants to compare them:

team_a = [1, 2, 3, 4, 5]

team_b = [5, 4, 3, 2, 1]

if team_a == team_b:

    print("Results are the same")

else:

    print("Results are different")

What will be printed when this code is executed?

View this question
A dictionary is used to store the color of fruits:

fruit_colors = {"Apple": "Green", "Banana": "Yellow"}

fruit_colors["Apple"] = "Red"

What is the value of fruit_colors after this code is executed?

0%
0%
0%
0%
View this question

Want instant access to all verified answers on elearn.squ.edu.om?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome