Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

DSCI 510 UCLA ¿ Principles of Programming for Data Science Discussion

DSCI 510 UCLA ¿ Principles of Programming for Data Science Discussion

DSCI 510 UCLA ¿ Principles of Programming for Data Science Discussion

Description

Q1.[1 point]


Instruction : You are given a txt file named ‘weather_report.txt’ on D2L, download it and keep it in the same location where you have this notebook.

For this problem on files, You are required to count the number of lines in the given text file.

Input: none
Output: int


Rubric: All or Nothing.
Grading Rubric: 1 point if the output is correct. 0 otherwise (No Partial Marks).


[18]

<pre>
<span class="mtk8"># Fill this function for your solution</span><span class="mtk6">def</span> <span class="mtk14">number_of_lines</span><span class="mtk1">():</span><span class="mtk1">    fhand = <span class="mtk14">open</span><span class="mtk1">(</span><span class="mtk26">'weather_report.txt'</span><span class="mtk1">)</span><span class="mtk1">    count = <span class="mtk11">0</span><span class="mtk18">for</span><span class="mtk1"> line <span class="mtk6">in</span><span class="mtk1"> fhand:</span><span class="mtk1">      count = count + <span class="mtk11">1</span><span class="mtk14">print</span><span class="mtk1">(</span><span class="mtk26">'Line Count:'</span><span class="mtk1">, count)</span></span></span></span></span>


[19]

<pre>
<span class="mtk8"># Do not change this cell <span class="mtk14">print</span><span class="mtk1">(number_of_lines())</span></span>


Q2.[4 points]

For the file weather_report.txt, you have 4 floating point numbers in each line as per the format below.

(Min Temperature(in C), Max Temperature(in C), Humidity%, Rainfall(in)) for a particular day.

You are given a prediction algorithm which has the logic that if Max temperature – Min temperature is greater than 10 and if humidity is greater than 50%, it is a rainy day else it is sunny.

If we predict a day to be rainy using the above algorithm and actual rainfall for that day in the dataset is greater than 0 then it’s correct else it’s a wrong prediction. Similarly, if we predict sunny and rainfall is 0, then it’s correct else it’s a wrong prediction.

Your task is to return the total number of correct predictions corresponding to the dataset and the prediction algorithm.

Note: Read data from the file.

Input: none Output: int


Rubric : All/Nothing
Grading Rubric: 4 points if output is correct. (0, otherwise)


[ ]

<pre>
<span class="mtk6">def</span> <span class="mtk14">model_accuracy</span><span class="mtk1">():</span><span class="mtk18">pass</span>

Q3 [2 points]

A String is determined to be fair if it satisfies any of the 3 conditions :

Every letter in the string is a capital, like “USC” (or) Every letter is not uppercase , like “assignment” (or) Only the initial character in the word is capital, like “This”.

Note : The input string will only have alphabets.

Input: String
Output: String

Example:

<code><span class="mtk1">Input  <span class="mtk1">USC</span><span class="mtk1">Output  <span class="mtk1">Fair</span></span></span></code>
<code><span class="mtk1">Input  <span class="mtk1">USb <span class="mtk1">Output  <span class="mtk1">Not Fair</span></span></span></span></code>

Grading Rubric: All or Nothing (+2 if All Cases pass, else 0)


[ ]

<pre>
<span class="mtk6">def</span> <span class="mtk14">is_fair</span><span class="mtk1">(</span><span class="mtk15">s</span><span class="mtk1">):</span><span class="mtk18">pass</span>

Q4 [3 points]

Hopefully you all remember the work with Palindromes in the previous Lab (Lab-3). Given a list of words, your task is to return the first palindromic string in the list. If the list has no such matching string then return an empty string “”.

Note: You can reuse any of your own functions from the previous labs, if need be.

Definition : A string is said to be a palindrome if it reads the same in both forward and backward directions.

Input: List of Strings Output: String

Example:

<code><span class="mtk1">Input  <span class="mtk1">words = ["asd","capital","aba","southern","califor</span><span class="mtk1">nia"]</span><span class="mtk1">Output  <span class="mtk1">'aba'</span></span></span></code>
<code><span class="mtk1">Input  <span class="mtk1">words = ["asddd","abcdefghi"] <span class="mtk1">Output  <span class="mtk1">''</span></span></span></span></code>

Grading Rubric: All or Nothing (+3 if All Cases pass, else 0)


[ ]

<pre>
 <span class="mtk6">def</span> <span class="mtk14">firstPalindrome</span><span class="mtk1">(</span><span class="mtk15">words</span><span class="mtk1">):</span><span class="mtk18">pass</span>


[ ]

<pre>
<span class="mtk8">#Sample example for you to test. Don't need to sub</span><span class="mtk8">mit this cell.</span><span class="mtk1">words = [</span><span class="mtk26">"asd"</span><span class="mtk1">,</span><span class="mtk26">"capital"</span><span class="mtk1">,</span><span class="mtk26">"aba"</span><span class="mtk1">,</span><span class="mtk26">"southern"</span><span class="mtk1">,</span><span class="mtk26">"california"</span><span class="mtk1">]</span>

[ ]

<pre>
<span class="mtk8"># Again another sample for you to call your functi</span><span class="mtk8">on. Just for you to test</span><span class="mtk1">firstPalindrome(words)</span>

Bonus [2 points]

Our favourite detective Sherlock has a been given a cipher to decode and needs your help. The key to the cipher is to solve a substring problem. He’s given a String X, consisting of just 2 characters ‘a’ and ‘b’, and wants to find out the number of substrings of X which start and end with the character ‘a’.

Your task is to find out the number of such subtrings.

Input: String
Output: int

Example:

<code><span class="mtk1">Input  <span class="mtk1">ababab</span><span class="mtk1">Output  <span class="mtk1">6</span></span></span></code>
<code><span class="mtk1">Input  <span class="mtk1">aa <span class="mtk1">Output  <span class="mtk1">3</span></span></span></span></code>

Grading Rubric: All or Nothing (+2 if All Cases pass, else 0)


[ ]

def count_substring(X):

pass


Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Essay Noon only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Essay Noon are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Essay Noon are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Essay Noon, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20