Question

In: Computer Science

Given the code snippet below, complete this program by: Displaying the data (temperatures) Displaying the minimum...

Given the code snippet below, complete this program by:

  1. Displaying the data (temperatures)
  2. Displaying the minimum temperature value
  3. Displaying the maximum temperature value
  4. Displaying the mean temperature

SUBMIT THE PYTHON FILE (.PY) NOT SCREENSHOT, WORD DOCUMENT ETC. IF YOUR SUBMISSION IS NOT A .PY FILE, AUTOMATIC ZERO.

#Code snippet below. Copy this into your favorite IDE and complete the tasks

import numpy as np

import pandas as pd

temps = np.random.randint(60, 101, 6)

temperatures = pd.Series(temps)

2.

Write a python program that asks the user to enter

a number of quarters, dimes, nickels and pennies and then outputs the monetary value of the coins in the format of

dollars and remaining cents. YOUR PROGRAM MUST HAVE AT LEAST ONE FUNCTION.

3.

USE THE python TextBlob library to create a language translation application. Your application should accept at least two input from the user. The first input should be the text to be translated (your program should accept any language). The second should be the language to translate to. At minimum, your program should be able to translate to 10 different languages.

Your program must have at least one python function.

Solutions

Expert Solution

The solutions are given below.

1.

The Python code is given below.

import numpy as np

import pandas as pd

#function to print the values

def display():

print('Displaying data:')

print(temperatures) #display temperatures

print('Minimum value:',max(temperatures)) #gets the max value

print('Minimum value:',min(temperatures)) #gets the min value

print('Mean value:',sum(temperatures)/6) #print mean by sum/6

temps = np.random.randint(60, 101, 6)

temperatures = pd.Series(temps)

display() #call the function to display values

If the indendations are not clear, then refer the screenshot of the code.

Output:

Explanation:

  • The max() function can be used to retrieve the largest element. Similarly, min() function can be used to find the smallest value from a set.
  • To find the mean, first find the total value using sum(), then divide it by the total number of elements. Here it is 6. So, sum(temperatures)/6 will return the mean value.

2.

The Python code is given below.

def value(q,d,n,p):

#set the default value

quarters=25

dimes=10

nickels=5

penny=1

cents=0

#calculate value

cents=quarters*q + dimes*d + nickels*n + penny*p

dollars=0

#convert cent to dollar

while(cents>=100):

dollars+=1

cents-=100

#display amount

print('$',dollars,'.',cents)

#main

#read the values

q=int(input('Enter the number of quarters: '))

d=int(input('Enter the number of dimes: '))

n=int(input('Enter the number of nickels: '))

p=int(input('Enter the number of pennies: '))

#pass the values to the function

value(q,d,n,p)

If the indendations are not clear, then refer the screenshot of the code.

Output:

Explanation:

  • Get the number of quarters, nickels, dimes and pennies from the user. Pass those values to the function.
  • Calculate the total value in cents by multiplying with the respective values.
  • If cent value is greater than 100, a while loop is used t0 convert it into dollar-cent format. In each iteration, a value of 100 will be decreased from cents and dollar is incremented by 1. Finally, the value is displayed.

3.

The Python code is given below.

#import textblob module

from textblob import TextBlob

def translate_to(text,lang):

tb=TextBlob(text)

print(tb.translate(to=lang))

#MAIN

#get text from the user for translation

text=str(input('Enter the text: '))

#get the language code for translation

lang=str(input('Enter the language for translation: '))

#call the function

translate_to(text,lang)

If the indendations are not clear, then refer the screenshot of the code.

Output:

Explanation:

  • Import the TextBlob module.
  • Input the text to be translated and store it to a variable called text.
  • Input the language code in which the text is to be translated. Store it to a variable lang.
  • Call the function and pass the two input value as arguments.
  • Create a constructor of the TextBlox.
  • Using translate(), translate the text to the given language.

Hope this helps. Doubts, if any, can be asked in the comment section.


Related Solutions

[50%] Code Snippet Given snippet code below that you are required to complete. You are not...
[50%] Code Snippet Given snippet code below that you are required to complete. You are not allowed to make a new function or change any given code. Please complete each section that are marked with the notation “INSERT YOUR CODE HERE”. Once you complete the snippet below, your output should have the same result with the given output below. Descriptions: [15%] isValid() This function is for checking that there is no duplicated employee data in the linked list. This function...
Given the below Java code snippet, assuming the code is correct, and the names are meaningful,...
Given the below Java code snippet, assuming the code is correct, and the names are meaningful, select the best answer for the below questions: public static void main(String[] args) { int numStations = 10; int enter = 0; int exit = 0; Train train = new Train(numStations); for (int station = 0; station < numStations; station++) {      enter = enter + train.enterPassengers(station);      exit = exit + train.exitPassengers(station); } System.out.println("Number of passengers entered the train: " + enter); System.out.println("Number...
Complete the below code so that your program generates a random walk on the given graph....
Complete the below code so that your program generates a random walk on the given graph. The length of your walk should also be random. /******************************************************************/ #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct NODE_s *NODE; typedef struct NODE_s{ char name; NODE link[10]; }NODE_t[1]; #define nodeA 0 #define nodeB 1 #define nodeC 2 #define nodeD 3 #define nodeE 4 #define nodeF 5 int main() { srandom(time(NULL)); //printf("%d\n", random()); NODE_t node[6]; node[nodeA]->name = 'A'; node[nodeB]->name = 'B'; node[nodeC]->name = 'C'; node[nodeD]->name...
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q =...
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); cout << *p; return 0; } Question 31 options: 10 20 compiler error Runtime error Question 32 A union’s members are exactly like the members of a Structure. Question 32 options: True False Question 33 Given the code below, what are the errors. #include <iostream> using namespace...
a) Find a bug in the code snippet below. Assume that a, b, c and d...
a) Find a bug in the code snippet below. Assume that a, b, c and d are correctly declared and initialized integer variables. a = b+c if (a=d) then print *,”A equals to D” else print *,”A does not equal D” end if b) Find a bug in the code snippet below. Assume that a,b,and c are correctly declared and initialized integer variables. if (a+b) > c) then print *,”Sum of A+B is greater than C” end if
1. Give the O-runtime depending on n for the code snippet below (n > 0). for(...
1. Give the O-runtime depending on n for the code snippet below (n > 0). for( j = n; j <= 0; j = j - 1)                                     for( k = 1; k <= n; k = k + 1)                                                 print(" "); 2. Give the O-runtime depending on n for the code snippet below (n > 0).            for( j = 1; j <= n; j = j + 1)                                     for( k = 1; k <= n; k =...
PYTHON COMPUTER CODE PROGRAMMING - DISPLAYING A PLOT OF TEMPERATURE VERSUS DEPTH WHEN GIVEN A LATITUDE....
PYTHON COMPUTER CODE PROGRAMMING - DISPLAYING A PLOT OF TEMPERATURE VERSUS DEPTH WHEN GIVEN A LATITUDE. PYTHON ASSIGNMENT. NOT SURE HOW TO PLOT THIS DATA WITH THE GIVEN INFO BELOW: Just as the atmosphere may be divided into layers characterized by how the temperature changes as altitude increases, the oceans may be divided into zones characterized by how the temperature changes as depth increases. We shall divide the oceans into three zones: the surface zone comprises the water at depths...
Using the provided Java program below, complete the code to do the following. You may need...
Using the provided Java program below, complete the code to do the following. You may need to create other data items than what is listed for this assignment. The changes to the methods are listed in the comments above the method names. TODO comments exist. Apply any TODO tasks and remove the TODO comments when complete. Modify the method findMyCurrency() to do the following:    a. Use a do-while loop b. Prompt for a currency to find. c. Inside this...
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI....
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI. Zip the solution project file and attach to this submission. Do this in the GUI format (Windows Form). Be sure and add a Clear Button to reset for entering another word or words. PigLatinGUI Basic Steps in Creating your Program Create your user interface (GUI). Use different font styles but don’t overdo it, Use colors, and Use graphics (You can find all kinds of...
Instructions: Using the following data, complete the requirements given below. When you are given amounts to...
Instructions: Using the following data, complete the requirements given below. When you are given amounts to assume as the answers to previous requirements, be careful to use such assumed amounts rather than your answers (in order to minimize carry-through errors). The Finishing Department of Curtis Corporation reports the following for January 2011: Production: All materials are added at the beginning of the process. Beginning work in process 20,000 units, 60% complete. Units started into production 240,000 units. Ending work in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT