mardi 1 juin 2021

This should be simple programme [closed]

How write java programme to prompt user to input non zero numbers and find sum & average of above numbers.when user input "0" sum and average should be displayed on the screen.use input box to input dat and massagebox to display the output.

Condition using char in Scheme

I'm trying to use char as a condition in my if-else statement but it seems the condition only can accept integer input.

This is my code:

(display "Presenter - R \nParticipant - P")

(define (option)
  (define r(read))
(cond
  ((= r R )
   (display "Presenter: \nLocal - RM1272\nInternational - RM1474"))
  ((= r P )
   (display "Participant: \nLocal - RM795\nInternational - RM800"))
))

Output:

Presenter - R 
Participant - P
> (option)
R
. . =: contract violation
  expected: number?
  given: r 

"else" option alternative is ignored in a while loop

This is probably a simple problem that requires a simple answer...but I have been scratching my head why this happens. It's a problem on the loop that I am testing. Here's the loop:

done = False
while done==False:
    checkUser = input("Do you want to continue?\nType Y or y to continue; any other char to quit\nType here: ")
    print(checkUser) # just to check the input

    if checkUser =='Y' or 'y':
        print ('Yes, I want to continue.')
        done = False
        break

    else:
        print('No. I want to quit now.')
        done = True
        sys.exit()

When I run this script on PyCharm, I get the outputs below:

Do you want to continue?
Type Y or y to continue; any other char to quit
Type here: y
y
Yes, I want to continue

Do you want to continue?
Type Y or y to continue; any other char to quit
Type here: n
n
Yes, I want to continue

Question: why is the "else" option ignored?

I tried so many variations like removing sys.exit() and so forth, but the loop still behaves the same way.

Iterate a list in a dictionary, if the list exists in the dictionary. In Python

I have a dictionary in the following format: (In Python)

some_dict = {
 'some_list': ['val1', 'val2', 'val3']
}

The key 'some_list', doesn't always exist, but when it does, I want to loop its values. To do this I'm currently doing the following:

if 'some_list' in some_dict:
 for value in some_dict['some_list']
  #Run some code using value

Is this the best / most simple way to achive this goal, or is there a way to check for existence and loop in one line?

Problem using the Len function in defining a condition in Excel

I want to give a two-column Excel file as input to my script. But I need a two-column Excel file to have one feature: the second column must have 10 characters. Because the number of rows in the Excel file is large, I can not manually edit every cell in the second column. So I need to put a control function in Excel to check the second column, so that it counts the number of characters in each cell in the second column and adds zero to the right of it, which is less than ten characters.

Based on my search, I realized that I could use the definition of the condition and the Len function, but the output was not what I wanted.

 Full ID       Expected Result
  15               0000000015
  159              0000000159
  16               0000000016
  43               0000000043
  4329             0000004329

What I had tried :

=Right(A2,LEN(A2)+8)

but it was wrong.

How can I get my expected results in like the top example?

Use if and else statement result as a variable in mysql

Good Day everyone,

I need help in using the result of my if and else satement as a variable in the mysql query below:

SELECT type, description, IF(type = 'Fixed Assets', 'true', 'false') AS description, IF(description = description, 'true', 'false') AS description2 FROM table_name;

What I need is to use the result of 'description' as a condition in another column which is 'description2', so that I won't use the same IF and else statement of 'description 'over and over again.

The expected result for description is 'true', and the expected result for description2 is 'true' as well because the value for description = 'true'.

Any answers will be a good help, thank you.

lundi 31 mai 2021

Evaluate multiple conditional statements with possible undefined variables

In Javascript, what would be the best way to evaluate several conditions when taking into consideration variables that could be undefined? For instance, I want to evaluate if x > y only if x is NOT undefined (has a value), and if it is undefined, continue to proceed to the next condition.

Something like:

if(x && x > y && a && a > b && c < d && e > f) ....

Here I want to see if x is defined, and then evaluate if x is greater than y, then go to evaluate if a is defined and evaluate if a is greater than b, then evaluate if c is less than d and etc. So here I want it so that if x or a is undefined CONTINUE to proceed to evaluate c < d and e > f

Here if the variables are are undefined then the whole statement is all false... what are some solutions for this that's clean?