Answer:
The solution code is written in Java.
- public class Main {
-
- public static void main(String[] args) {
-
- Scanner inNum = new Scanner(System.in);
- System.out.print("Enter number of toss: ");
- int num = inNum.nextInt();
-
- for(int i=0; i < num; i++){
- System.out.println(toss());
- }
- }
-
- public static String toss(){
- String option[] = {"heads", "tails"};
- Random rand = new Random();
- return option[rand.nextInt(2)];
- }
- }
Explanation:
Firstly, we create a function <em>toss()</em> with no parameter but will return a string (Line 14). Within the function body, create an option array with two elements, "heads" and "tails" (Line 15). Next create a Random object (Line 16) and use <em>nextInt()</em> method to get random value either 0 or 1. Please note we need to pass the value of 2 into <em>nextInx() </em>method to ensure the random value generated is either 0 or 1. We use this generate random value as an index of <em>option </em>array and return either "heads" or "tails" as output (Line 17).
In the main program, we create Scanner object and use it to prompt user to input an number for how many times to toss the coin (Line 6 - 7). Next, we use the input num to control how many times a for loop should run (Line 9). In each round of the loop, call the function <em>toss() </em>and print the output to terminal (Line 10).
Answer:
Complete question is:
write the following decorators and apply them to a single function (applying multiple decorators to a single function):
1. The first decorator is called strong and has an inner function called wrapper. The purpose of this decorator is to add the html tags of <strong> and </strong> to the argument of the decorator. The return value of the wrapper should look like: return “<strong>” + func() + “</strong>”
2. The decorator will return the wrapper per usual.
3. The second decorator is called emphasis and has an inner function called wrapper. The purpose of this decorator is to add the html tags of <em> and </em> to the argument of the decorator similar to step 1. The return value of the wrapper should look like: return “<em>” + func() + “</em>.
4. Use the greetings() function in problem 1 as the decorated function that simply prints “Hello”.
5. Apply both decorators (by @ operator to greetings()).
6. Invoke the greetings() function and capture the result.
Code :
def strong_decorator(func):
def func_wrapper(name):
return "<strong>{0}</strong>".format(func(name))
return func_wrapper
def em_decorator(func):
def func_wrapper(name):
return "<em>{0}</em>".format(func(name))
return func_wrapper
@strong_decorator
@em_decorator
def Greetings(name):
return "{0}".format(name)
print(Greetings("Hello"))
Explanation:
Answer:
k = 4.21 * 10⁻³(L/(mol.s))
Explanation:
We know that
k = Ae ------------------- euqation (1)
K= rate constant;
A = frequency factor = 4.36 10^11 M⁻¹s⁻¹;
E = activation energy = 93.1kJ/mol;
R= ideal gas constant = 8.314 J/mol.K;
T= temperature = 332 K;
Put values in equation 1.
k = 4.36*10¹¹(M⁻¹s⁻¹)e
k = 4.2154 * 10⁻³(M⁻¹s⁻¹)
here M =mol/L
k = 4.21 * 10⁻³((mol/L)⁻¹s⁻¹)
or
k = 4.21 * 10⁻³((L/mol)s⁻¹)
or
k = 4.21 * 10⁻³(L/(mol.s))
Answer:
power developed by the turbine = 6927.415 kW
Explanation:
given data
pressure = 4 MPa
specific enthalpy h1 = 3015.4 kJ/kg
velocity v1 = 10 m/s
pressure = 0.07 MPa
specific enthalpy h2 = 2431.7 kJ/kg
velocity v2 = 90 m/s
mass flow rate = 11.95 kg/s
solution
we apply here thermodynamic equation that
energy equation that is
put here value with
turbine is insulated so q = 0
so here
solve we get
w = 579700 J/kg = 579.7 kJ/kg
and
W = mass flow rate × w
W = 11.95 × 579.7
W = 6927.415 kW
power developed by the turbine = 6927.415 kW