Getting "Wrong number of arguments to IF..." error - google-sheets-formula

I'm trying to create a logic in google sheets. But getting the error "Wrong number of arguments to IF. Expected between 2 and 3 arguments, but received 4 arguments."
I have tried this formula. It works if the number is upto 45000. It shows error if the number goes byound that.
IF(B4<20000, 0, IF(B4>20000, ROUND(IF(B4<34286,685,IF(B4<45714,1715,IF(B4<57143,3200,IF(B4<68571,5140,IF(B4>68571,6860,0)),0))))))

use:
=IF(B4<20000, 0,
IF(B4>20000, ROUND(
IF(B4<34286, 685,
IF(B4<45714, 1715,
IF(B4<57143, 3200,
IF(B4<68571, 5140,
IF(B4>68571, 6860, 0))))), 0)))

Related

`*': negative argument (ArgumentError) Ruby

I keep getting this negative argument error when running this code in the Codewars IDE. It runs fine in terminal but in Codewars it both passes the test and runs this error message simultaneously.
STDERR
main.rb:5:in `*': negative argument (ArgumentError)
from main.rb:5:in `maskify'
from main.rb:9:in `<main>'
The code is
def maskify(cc)
x = cc.to_s
y = "#" * (x.length - 4)
return y + x.slice(-4..-1)
end
I'm new to Ruby but I've not heard anywhere that it has a problem with negative numbers being used in .slice. Am I missing something here? Thanks.
You're not considering cases when cc is shorter than 4 symbols.
And expression "#" * (x.length - 4) raises the error because you can't multiply a string by a negative number.
Try to use Array#max method to handle this:
"#" * [x.length - 4, 0].max

What is the number after the second colon on a Google Apps Script error?

I have a Google Apps Script linked to a Sheet that takes Form responses. I'm getting this error:
I've figured out that 104 is the line number where the error occurs. What does 14 represent? Both numbers are the same every time the error occurs. For context's sake, here's some of the code:
if (Renaming) {
Debug("Renaming Began")
var Section = Values[4]
var Name = Values[5].replace(/\//g, "-").concat(" ", Values[3], "-", Values[2].substring(0, 1)) // Date, space, last name, hyphen, first initial
Debug("Renaming Files...")
DriveApp.getFileById(Documents[0]).setName(Section.concat(" Session Plan ", Name)) // Session plan naming (this is line 104)
Debug("Session Plan Renamed")
DriveApp.getFileById(Documents[1]).setName(Section.concat(" Sign-in ", Name))
Debug("Sign-in Sheet Renamed")
if (Documents.length > 2) {
Debug("Worksheets Detected")
Debug(Documents.length)
for (i = 2; Documents.length; i++) {
if (i > 13) {break}
Debug(("Began ").concat(i))
if (!Documents[i]) {continue}
Debug(("Exists ").concat(i))
DriveApp.getFileById(Documents[i]).setName(Section.concat(" Worksheet #", i - 1, " ", Name))
Debug(("Renamed ").concat(i))
}
Debug("Worksheets Renamed")
}
Debug("Renaming Completed")
} else {
Debug("Renaming Disabled")
}
Explanation:
From this expression: 104:14:
104: represents the row where the error occured.
14: represents the column where the error occured.
Column is defined as the position of each character in the document on the horizontal axis. Each symbol/space/letter/number occupies one column of space.
Example:
the error here is in the 2nd row and there are 2 spaces (columns) before the word error.
But the error starts at the letter e of the word error. So you have 2 spaces (columns) before error plus a letter which is the position where the error started. Two spaces and one letter equals to 3 columns. Therefore, you have an error that is located in the 3rd column.
In your case, the error is located at the row 104 and there are 13 symbols/spaces/letters or numbers before the command that introduces the error. Everything before column 14 is correct. The error starts at column 14.

sort_values() got multiple values for argument 'axis'

sort_values() got multiple values for argument 'axis'
I am trying to sort this series using sort_values
Item Per Capita GSDP (Rs.)
Andhra_avg 102803
Arunachal_avg 100745
Assam_avg 55650.6
Bihar_avg 30030.6
Chattisgarh_avg 82046.7
Gujrat_avg 128755
Himachal_avg 126650
Jharkhand_avg 56385
Jammu_avg 73422.8
Karnataka_avg 128959
Kerala_avg 139140
MP_avg 61122.2
Maharashtra_avg 133512
my code:
dfGDP_percapita.sort_values("Item", axis = 0, ascending = True, inplace = True, na_position ='first')
Expected result should give "Per Capita GSDP (Rs.)" in the decreasing order with Nan on top
Try changing your code to
dfGDP_percapita.sort_values("Item", inplace=True, na_position ='first')
Some of the arguments are by default - I'm not sure why the error occurs, but my code works like this.

Runtime error claiming a negative or zero argument to the logarithm function in Box-Mueller algorithm

The following code is a part of a Fortran 90 program that I wrote in Plato IDE:
It is just the Box-Mueller algorithm to generate Gaussian random numbers.
Program brownstep2_single_stage
Integer:: i,j,m,n,countsucc!,a
Real:: dt,D,epsa,r1,r2,w,fptsum,fptdef1,fptdef2
Real,Dimension(0:100002) :: fx !gt
!T=1000.0 and n*dt=T
dt=0.001
m=100000
n=100000
D=1.0
!a=7
w=2
epsa=0.00001
fx(0)=6.0
!gt(0)=0
fptsum=0
countsucc=0
Call random_seed()
Do i=0,m
!Call random_seed(a)
Do j=0,n
Do while (w>=1.0.and.w<0.0)
Call random_number(r1)
Call random_number(r2)
!r=rand()
r1=2.0*r1-1
r2=2.0*r2-1
w=r1*r1+r2*r2
End do
w=sqrt((-2.0*log(w))/w)
r1=r1*w
r2=r2*w
If(mod(j,2)==0) then
w=r1
Else if(mod(j,2)==1) then
w=r2
End if
fx(j+1)=fx(j)+w*sqrt(2.0*D*dt)
If(fx(j+1)<epsa) then
fptsum=fptsum+(j+1)*dt
countsucc=countsucc+1
exit
End if
print *,i,j
End do
End do
fptdef1=fptsum/m
fptdef2=fptsum/countsucc
print *,'The value of fpt by 1st definition is:',fptdef1
print *,'The value of fpt by 2nd definition is:',fptdef2
print *,'The number of successful events is:',countsucc
print *,'The total number of events is:',m
End program brownstep2_single_stage
During compilation, it shows no error, but when run, it shows the following runtime error, claiming a negative or zero argument to the logarithm function.
Runtime error from program:e:\my files\sample2brownstep_gauss.exe
Run-time Error
Error: Negative or zero argument to logarithm routine
BROWNSTEP2_SINGLE_STAGE - in file sample2brownstep_gauss.f90 at line 31 [+02cc]
What should I do to avoid this?
The changed code above still has problems. w is still not set before the do while loop is reached for the first time and w is used in the condition. Use an 'infinite' do loop with an exit statement. This ensures that one attempt at w is always attempted. This would be better:
do
Call random_number(r1)
Call random_number(r2)
r1=2.0*r1-1
r2=2.0*r2-1
w=r1*r1+r2*r2
if (w .lt. 1.0) exit
End do
w=sqrt((-2.0*log(w))/w)
r1=r1*w
r2=r2*w

Why does ruby koans accept the exception message in line 5 but not in line 10?

1. def test_calling_global_methods_with_wrong_number_of_arguments
2. exception = assert_raise(ArgumentError) do
3. my_global_method
4. end
5. assert_match(/wrong number of arguments \(0 for 2\)/, exception.message)
6.
7. exception = assert_raise(ArgumentError) do
8. my_global_method(1,2,3)
9. end
10. assert_match(/wrong number or arguments \(3 for 2\)/, exception.message)
11. end
line 5 worked perfectly. But when i make the same edit in line 10, why do i get the error message saying: Expected "wrong number of arguments (3 for 2)" to match /wrong number or arguments \(3 for 2\)/
Am i missing something?
You have a typo in the assertion in line 10, 'or' instead of 'of'
wrong number or arguments

Resources