I am doing a school program again and when I enter <= on a range eg. >= 95 and <= 100 I get told the less than or = in <= is a syntax error.
since I can't type copy and paste the code without errors here this is the code in full so far
You need the variable in both paths of the expression: if var >= 96 and var <= 100:
Related
I have a PDF form that adds up several different answers and displays the sum of these answer at the bottom of the page. I want to take that number, and have a sentence underneath it display three different options depending on the sum.
Greater than 60: Proceed
between 45 & 60: Consult Sales Lead
Less than 45: Decline
I am attempting to run a custom calculation script that takes the sum (which is named "total") and writes the above options, but I'm running into a myriad of errors.
My code I've written is below
var A = this.getField("total").value;
if (A >= 60){
event.value = "Proceed";
} else {
if (A <= 45){
event.value = "Decline";}
} else {
if (A < 60 && A > 45){
event.value = "Proceed, decision made with sales leader";}
}
If I were to only write the below block, I do not get any errors.
var A = this.getField("total").value;
if (A >= 60){
event.value = "Proceed";
}
I'm a newbie when it comes to most JavaScript, so any help is greatly appreciated! Thanks in advance!
I have based most of my code off of different search results from google. My main source
example 1
Below are a few other links I've referenced
example 2
example 3
You can leave away the
if (A < 60 && A > 45) {
line, because that condition is always true after the two previous conditions.
And then, it should work properly.
Just if you want to stay with that last condition, you would have to close it with a curly brace.
I think I managed to figure it out! For some reason, the addition of the "else" factor was causing syntax errors, so I tried it without and it seems to work as intended!
My code, for anyone that happens to find this, is the following:
var A = this.getField("total").value;
if (A >= 60) {event.value = "Proceed";}
if (A <= 59 && A >= 46) {event.value = "Proceed, decision made with sales leader";}
if (A <= 45) {event.value = "Decline";}
if (A == 0) {event.value = " ";}
Thanks to everyone that took a look at this, even if you didn't get to comment before I figured it out!
So I've got a number guessing game, all my previous code works fine, and you can probably see that I have the randomly generated number printed on the screen. But when I guess the number correctly I still get told I am wrong?
num = randrange(0, 100)
if num > 0 and num < 50:
print("The number is greater than 0 but smaller than 50")
elif num > 50 and num < 100:
print("The number is smaller than 100 but greater than 50")
print(num)
print('Start Guessing')
a = input()
a = input()
if a == num:
print ("You got the correct number, woohoo")
elif num > 0 and num < 20:
print ("Hint: The number is bigger than 0 but smaller than 20")
elif num > 20 and num < 40:
print ('Hint: The number is bigger than 20 but smaller than 40')
elif num > 40 and num < 60:
print ('Hint: The number is bigger than 40 but smaller than 60')
elif num > 60 and num < 80:
print ('Hint: The number is bigger than 60 but smaller than 80')
elif num > 80 and num < 100:
print ('Hint: The number is bigger than 80 but smaller than 100')
Sorry for the weird looking code, I've never used this site before.
Your code appears to be Python. You should indicate that in a tag. Also, since Python if statements rely on indentation you should post your code with proper indentation.
In the code:
a = input()
if a == num:
You are comparing a string to a number. You should cast a to an int.
if int(a) == num:
if age < 20 then agecat=1;
else if age < 50 then agecat=2;
else if age ge 50 then agecat=3;
else if age=. then agecat=9;
I can't figure out where the logic error is or how to fix it. The only thing I can think of is a data validation line to make sure that, although the age variable is less than 20, that it's not a negative number. Any help would be appreciated.
I'm teaching myself C++ and was writing some code to calculate grade averages with arrays. Everything works except for when I try to display the results. I get the error "expected primary-expression before '<' token" on this line of code.
if(grade1 >= 0 && < 60)
followed by a single cout statement and a semi-colon. I looked in the book I am using and on c++ forums. My book looks just like my example and online everyone was missing a semi-colon or something else. Is that my case too?
Thanks!
You need to include 'grade1' on both comparisons.
if (grade1 >= 0 && grade1 < 60)
What you want is this:
if(grade1 >= 0 && grade1 < 60)
You need to provide a variable for each condition in your if statement. The grade1 variable will not carry over for other comparisons.
You must write like this
if (grade1 >= 60 && grade1 < 60){ //code here }
I'm writing a small program that requires a few if statements like so:
number=x/(y*y)
if number <5:
print "blahblahblah"
if number >5 or <10:
print "blahblahblah"
if number >10.5 or >15.0:
print "blahblahblah"
if number >15:
print "blahblahblah"
Basically I'm having trouble with using both > and < in my if statement and can't work out how to say "if less than 4 or more than 5"
When I load the program I get the following error -
Invalid syntax
Your code contains at least one syntax error, meaning it is not legal jython.
Any help would be greatly appreciated
Here you go:
if number > 10 and number < 20 then:
print "Number between 10 and 20"
Each comparison is an independent expression, combined together with and, or, etc.
As an addition to Paul answer with or, and etc you can use if 5 < number < 10::
if number < 5:
print("a")
if 5 < number < 10:
print("b")
if 10 < number < 15:
print("c")
if number > 15:
print("d")
You can also use elif (short of else if) and else which I prefer:
if number < 5:
print("a")
elif number < 10:
print("b")
elif number < 15:
print("c")
else:
print("d")
BTW in your code you used or instead of and.