Answer:
- import math
-
- def standard_deviation(aList):
- sum = 0
- for x in aList:
- sum += x
-
- mean = sum / float(len(aList))
-
- sumDe = 0
-
- for x in aList:
- sumDe += (x - mean) * (x - mean)
-
- variance = sumDe / float(len(aList))
- SD = math.sqrt(variance)
-
- return SD
-
- print(standard_deviation([3,6, 7, 9, 12, 17]))
Explanation:
The solution code is written in Python 3.
Firstly, we need to import math module (Line 1).
Next, create a function standard_deviation that takes one input parameter, which is a list (Line 3). In the function, calculate the mean for the value in the input list (Line 4-8). Next, use the mean to calculate the variance (Line 10-15). Next, use sqrt method from math module to get the square root of variance and this will result in standard deviation (Line 16). At last, return the standard deviation (Line 18).
We can test the function using a sample list (Line 20) and we shall get 4.509249752822894
If we pass an empty list, a ZeroDivisionError exception will be raised.
Answer:
See explaination
Explanation:
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void getName(string);
void getPin(int,int);
void displayMenu(int);
string name;
int pin1, pin2, ch ;
int main()
{
cout << fixed << showpoint << setprecision(2);
getName(name);
getPin(pin1,pin2);
displayMenu(ch );
system("pause");
}
void getName(string name)
{
cout << "Enter your name: ";
cin >> name;
if (name = "AXBY") || (name != "ABGSHY"))
{
getName(name);
}
}
void getPin(int pin1, int pin2)
{
string name;
if (name == "AXBY")
{
cout << "Please Enter Pin: ";
cin >> pin1;
if (pin1 != 4433)
{
cout << "Pin incorrect please try again!";
cin >> pin1;
}
}
if (name == "ABGSHY")
{
cout << "Please Enter Pin: ";
cin >> pin2;
if (pin2 != 2849)
{
cout << "Pin incorrect please try again!";
cin >> pin2;
}
}
}
void displayMenu(int ch )
{
cout << "[1] Check your account Balance\n"
"[2] Withdraw funds\n"
"[3] Deposit funds\n"
"Please Enter Choice: ";
cin >> ch ;
if (ch != 1 || ch != 2 || ch != 3)
{
cout << "Choice is incorrect, enter choice now: ";
cin >> ch ;
}
}
Answer: str[0].toUpperCase();
Explanation:
str[0] is pointing to the first character of the entire string and the code str[0].toUpperCase() will convert the characters to upper case if they are in lowercase and will remain unchanged if they are already in upper case.
The closest line to that would be the first line:
#!/bin/bash
echo "Hello World!"
BTW, the "#!" is referred to as a she-bang. When those are the first characters executed, the (requires an absolute path) program that follows is launched, and the rest of this file is given to it as data. To run this like a program, the execute permissions need to be set ( chmod 0755 script.sh ).