Answer:
1.
DIM myArray(10) as INTEGER
LET A = 0
FOR I = 1 TO 10 STEP 2
INPUT “INPUT NUMBER”; myArray(i)
LET A = A + myArray(i)
NEXT
PRINT A
END
2.
REM PROGRAM FOR CALCULATING THE SIMPLE INTEREST
CLS
INPUT “INPUT THE PRINCIPAL”; P
INPUT “INPUT THE TIME”; T
INPUT “INPUT THE RATE”;R
SI = P* T * R / 100
PRINT “SIMPLE INTEREST =”; SI
END
Explanation:
Please find the respective programs in the answer section.
Answer:
Following are the code to this question:
def get_initials(the_name): #defining a method get_initials
name = the_name.split(" ") #defining name variable that splits value
val = ''#defining a string variable val
for n in name: #defining loop to convert value into upper case and store first character
val = val + n[0].upper() + "." # use val variable to hold value
return val # return val
print(get_initials("Gloria kind of a big deal Tropalogos"))#call method and print return value
print(get_initials("Homer J Simpson"))#call method and print return value
print(get_initials("John Q Public")) #call method and print return value
Output:
J.Q.P.
H.J.S.
G.K.O.A.B.D.T.
Explanation:
In the given code, the last is incorrect because if we pass the value that is "Gloria kind of a big deal Tropalogos" so, will not give G.O.O.D. instead of that it will return G.K.O.A.B.D.T. So, the program description can be given as follows:
- In the given python code, a method "get_initials" is declared, that accepts "the_name" variable as a parameter, inside the method "name" variable is declared, which uses the split method that splits all values.
- In the next step, a string variable "val" and for loop is used, in which the "val" variable converts the first character of the string into the upper case and stores its character with "." symbol in "val" variable and return its value.
- In the last step, the print method is used, that passes the string value and prints its sort value.
Answer:
In Python:
def fib(nterms):
n1, n2 = 1, 1
count = 0
while count < nterms:
term = n1
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
return term
Explanation:
This line defines the function
def fib(nterms):
This line initializes the first and second terms to 1
n1, n2 = 1, 1
This line initializes the Fibonacci count to 0
count = 0
The following while loops gets the number at the position of nterms
<em> while count < nterms:
</em>
<em> term = n1
</em>
<em> nth = n1 + n2
</em>
<em> n1 = n2
</em>
<em> n2 = nth
</em>
<em> count += 1
</em>
This returns the Fibonnaci term
return term
A batholith is an intrusive igneous rock.