# Bash, how to calculate total from loop output

Please assist on that matter, I am trying to get a total number from loop that outputs 4 numbers as shown below: #!/bin/bash Bank=4 for ((out=1; out<=\$Bank; out++)) do echo \$out done I am getting output that looks like that: 1 2 3 4 How can I calculate 1+2+3+4 and get that calculated output 10… Read More Bash, how to calculate total from loop output

# Change value every nth iteration python

How can I change a value inside a loop every 10th iteration? Say I have a list with 30 properties myList = {"One", "Two", "Three", "Four"……..,"Thirty" } #trimmed listLength = len(myList) #30 listRange = range(0, listLength) # 0-30 for i in listRange x = ??? … ops.mesh.add(size=2, location=(x)) # change value of x by 10… Read More Change value every nth iteration python

# Replacing the Alphabet with a Numerical Value

I’ve been trying to solve this problem, I’m not allowed to use libraries or modules for my solution and I am required to use loops: Replace every letter with its position in the alphabet. If anything in the text isn’t a letter, ignore it and don’t return it. "a" = 1, "b" = 2, etc.… Read More Replacing the Alphabet with a Numerical Value

# printing exclusive multiplication of two numbers under 100

3-9. Print the exclusive multiple of two numbers After inputting two numbers, print out all the numbers from 1 to 100 that are multiples of only one of the two numbers. That is, a number that is a common multiple of the two numbers should not be output. For example, if 15 and 20 are… Read More printing exclusive multiplication of two numbers under 100

# looping in a Data frame

I’m pretty new in R and I would like to know why this operation doesn’t allow me to keep looping through a data frame. I have a dataframe filled with the following data (take note that it only has one column): 1,230.1,37.8,69.2,22.1 <– this is treated as a column like "1,230.1,37.8,69.2,22.1" 2,44.5,39.3,45.1,10.4 3,17.2,45.9,69.3,9.3 4,151.5,41.3,58.5,18.5 5,180.8,10.8,58.4,12.9… Read More looping in a Data frame

# How will the value of i be incremented here?

This is a approach for Weather a number is prime or not QUESTION: int main() { int i, num, b; printf("ENTER A NUMBER : \n"); scanf("%d", &num); for (i = 2; i <= num – 1; i++) { if (num % i == 0) break; } if (i == num) printf("PRIME"); else printf("NOT A PRIME");… Read More How will the value of i be incremented here?

# R: Printing Every 5th Output of a Loop

I am working with the R programming language. I have this loop: for (i in 1:100) { num_i = as.integer(rnorm(1,100,100)) print(num_i) }  44  -3  -55  127  149  83  151  52  120  102  132  352  96  208  268  156 … Read More R: Printing Every 5th Output of a Loop

# Making a loop to calculate [n] – [n+1] inside a single python list

I’m trying to calculate, with a loop, a substraction between n element and n+1 element inside a single python list. For exemple : list = [26.5, 17.3, 5.9, 10.34, 3.87] # expected calculation # 26.5 – 17.3 = 9.2 # 17.3 – 5.9 = 11.4 # … # expected result # list_2 = [9.2, 11.4,… Read More Making a loop to calculate [n] – [n+1] inside a single python list

# Is there a way to turn this into a loop?

Is there a way to turn this into a loop, where the city names (berlin, munich, hamburg, cologne) are looped in the calculations as well as in the print? If so, how do i do it? max_b = airquality_berlin[‘NO2’].max() min_b = airquality_berlin[‘NO2’].min() print(f"The inter-annual range of NO2-concentration in Berlin is: {max_b-min_b}\n") max_b = airquality_munich[‘NO2’].max() min_b… Read More Is there a way to turn this into a loop?