In: Computer Science
Given the code snippet below, complete this program by:
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.
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:
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:
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:
Hope this helps. Doubts, if any, can be asked in the comment section.