Expect script accepting negative numbers but not positive numbers - expect

I have an expect script that is working if I pass it in a negative number. However, it will now not accept positive numbers. The values I am trying to pass are -12345 and 12345. Here is my script:
spawn -noecho $servicecode --enable
expect "Do you want to continue*" { send "y\n" }
expect "password:" { send "${password}\n" }
expect "passcode:" { send -- "${passcode}\n" }
expect "*Service has been successfully enabled*"
expect eof
EOF
Now, if I remove the "--" from the expect statement, it now accepts positive integers but will no longer accept negative integers. If I put back the "--", it accepts negative numbers but now not positive numbers.
Can anyone help me in figuring out how to send both positive and negative integers?

Related

Catch multiple exceptions with specific error messages leading to one exit command

I'm trying to create a program that prompts the user for their weight in pounds as a float, when entered I need to check the entry to ensure that it is not a string or below the value of 10. It needs to be done in an if statement and not a loop, as well I need to be able to end multiple exceptions with one quit() statement instead of multiple quit() statements for each exception and then continue the program further if the user entered the input in the correct parameters.
This is what I have so far:
isvalid = float,int
try:
weight_pounds = float(input("Enter your weight in pounds: ")
if weight_pounds != isvalid:
print("Cannot be alphabetical.")
elif weight_pounds < 10:
print("Cannot be less than 10.")
else:
input("Press enter to exit...")
quit()
I am still learning basic functions of python and I may be missing something simple here but I've tried many ways to get this to work and I can't seem to get it working without either a dead end or ValueErrors.

Having trouble with a coding problem, can someone help me out?

I am very new here and to coding in general so apologies in advance for any mistakes in my questions and code.
I am currently working on this problem:
Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, I-405 services I-5, and I-290 services I-90. Note: 200 is not a valid auxiliary highway because 00 is not a valid primary highway number. Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.
EX: if the input is:
290
the output is:
I-290 is auxiliary, serving I-90, going east/west.
My code is currently as shown:
#include iostream
using namespace std;
int main()
{
int A; // A is the value for the Auxiliary highway
// This message will display when the code is run//
cout << "Please enter the three digit Auxiliary highway number" << endl;
cin >> A; // User inputs the Auxiliary highway number
do A-= 100;
while (A>100);
I am not sure what I am doing but I have no clue how to go about this so I am first starting with the second part(trying to make the code understand that if I am at the auxiliary number of I-290 then I would be servicing I-90). I tried this by trying to subtract 100 when the value for A was over 100 which would in theory leave me with a 2-digit number that would be the interstate highway number. I know that an error will happen when a number that ends in two zeros is entered so I planned to just use an if-else statement at the beginning of the code that would essentially just prevent this but, again, no clue how to do it but I think it may work
The first thing you want to do with a problem like this is think through it step by step. How do you solve this problem as a human with a pen and paper if you are given a highway number?
First you need a piece of code to tell you if the number is primary, so the code needs to tell you if the number is less than or equal to 99, if yes, then it is primary, if no, then it is auxillary.
In the case that is is not primary, you need a piece of code to tell you what the last 2 digits are of the number. The easiest way to do this is to convert the number to a string and remove the first character, and then convert back into an integer.
Lastly, you need a piece of code that tells you whether the primary road runs north/south, or east/west. So you need to check whether the number is even or odd. The easiest way to do this is to use the modulo function (x%2==y). If y is equal to zero, then you know the road runs east/west, otherwise it runs north south.
Hopefully you can see that the problem is a series of little problems that you can solve 1 by 1 to get the full solution. Problems become a lot less scary then.
I'm afraid I don't know C++ that well to give you a coded solution, but hopefully you can figure it out from here. It will be good practice for you to work through it because a lot of programming is about banging your head against a wall until you figure out the solution.
There are many ways to solve this problem. Here is one:
first, fix your header
#include <iostream>
accept user "highwayNumber"
cin >> highwayNumber;
write an if loop to determine highway properties:
if(highwayNumber > 0 && highwayNumber < 100){
highwayType = "primary";
//determine if highwayNumber is even or odd
if(highwayNumber % 2 == 0){
primaryType = “east-west”;
} else {
primaryType = “north-south”;
}
} else if (highwayNumber >= 100 && highwayNumber <= 999){
highwayType = “auxiliary”;
//determine what primaryHighway the auxiliaryHighway services
auxiliaryServiced = highwayNumber % 100;
} else {
cout << "invalid highway number” << end;
}
print output to user

How to detect number in certain range

Trying to get bot to send a message when the person sends a message in range
async def on_message(message):
if 0 < Message < 100 in message.content:
await bot.message.send(message.channel, "you are in Bronze 1")
Ok first of all. Please don't code on mobile. Especially not python. That will mess things up way too much.
Second, please define your variables properly. Message is not a defined variable. It will return an error.
So, as you said, you wanted two ways to do this. The number should be the message itself, or within the message.
For the first example, all you have to do is cast the message.content to int. Then you can check if it's in the range.
if 0 < int(message.content) < 100:
...
For the second example, you will have to do something similar, however, you should split the entire message.content string and convert the number ones into integers. I'm assuming that the number will not be within a word and it will be by itself.
for word in message.content.split():
if word.isnumeric():
num = int(word)
if 0 < num < 100:
... # return and send message to avoid spamming

can you use compound conditions in an if statement in pseudocode?

for example this simple program which tests if 3 numbers are in ascending order
if a1<a2 then
if a2<a3 then
write "the numbers are in ascending order";
else
write "the numbers are not in ascending order";
endif
else
write "the numbers are not in ascending order;
endif
am i allowed to write it like this in pseudocode?
if (a1<a2 and a2<a3)
write "the numbers are in ascending order";
else
write "the numbers are not in ascending order";
Yes. As long as it's understandable and can easily be converted to real source code, it's fine as pseudocode.

Timeout_value error in process when using timer:sleep(rand:uniform()*1000)

Trying to use timer:sleep(rand:uniform()*1000) in Erlang to create a random sleep period, but receive the following error:
Error in process <0.45.0> with exit value:
{timeout_value,[{timer,sleep,1,[{file,"timer.erl"}}]
Why might I be receiving this error?
rand:uniform()*1000 is a floating point value while timer:sleep/1 only accepts integers. You can use trunc to convert the float to integer (discarding the value after the .):
timer:sleep(trunc(rand:uniform()*1000)).
or, even better, use rand:uniform/1 to generate a random integer between 1 and N directly:
timer:sleep(rand:uniform(1000)).

Resources