if-statement

How can I write a neater set of code for my rock paper scissors game?

纵饮孤独 提交于 2021-02-05 06:58:56
问题 Below is my JS file for a rock, paper, scissors game activity we had to do in my web development class. I was able to get everything to work, however I do not like how long my if-else statements made my code and was wondering how can I make this more concise and have it in less lines of code. const imagePath=[]; imagePath.push("img/paper.png"); imagePath.push("img/rock.png"); imagePath.push("img/scissors.png"); let counter=1; let counter2=1; let images=document.querySelector("#player"); let

Why an IF block is allowed inside another IF that doesn't have curly brackets in JAVA [duplicate]

妖精的绣舞 提交于 2021-02-05 06:54:44
问题 This question already has answers here : Is there a difference in removing the curly braces from If statements in java (17 answers) Closed 7 years ago . Normally in JAVA if an IF statement doesn't have curly brackets can have only one line that is executed when IF condition is met, however if another IF block (inner IF) follows the initial IF, then no error is triggered and there are more lines. How is this possible? Example if (true) if (true) System.out.println("true"); else System.out

R: string list in ifelse

浪子不回头ぞ 提交于 2021-02-05 06:51:28
问题 I am looking for something comparable to the "where 'var' in (...)" statement in MySQL. My code is as follows: data<-data.frame(id=10001:10030,cc1=rep(c("a","b","c"),10)) attach(data) data$new<-ifelse(cc1=="a"|cc1=="b",1,0) What is a better way to include a list of strings in the ifelse instead of using | ? Something like: ifelse(cc1 in ('a','b'),1,0) Many Thanks! 回答1: ifelse(cc1 %in% c("a", "b"), 1, 0) Or simply: as.numeric(data$cc1 %in% c("a", "b")) Avoid using attach though. It makes

R: Sum until 0 is reached and then restart

无人久伴 提交于 2021-02-04 21:30:09
问题 Adding on to what's already being said or commented on this post: Cumulative sum until maximum reached, then repeat from zero in the next row I've a similar dataframe which has about 50k+ observations. This dataframe was being read from a csv file and is an outcome of several operations already performed on it. Pasting a sample here: Home Date Time Appliance Run value 679 2 1/21/2017 1:30:00 0 1 0 680 2 1/21/2017 1:45:00 0 1 0 681 2 1/21/2017 2:00:00 0 1 0 682 2 1/21/2017 2:15:00 0 1 0 683 2

Concise way to compare a variable against multiple values [duplicate]

…衆ロ難τιáo~ 提交于 2021-02-04 19:57:15
问题 This question already has answers here : Why does checking a variable against multiple values with `OR` only check the first value? [duplicate] (4 answers) Closed 8 months ago . I've been trying to understand if it is possible to use an if statement similar to the likes of what I have demonstrated here below. It is my understand that it is not? for i in range(10): if i == (3 or 5) or math.sqrt(i) == (3 or 5): numbers.append(i) With this block of code I only get the numbers 3 & 9 , while I

Using ifelse statement for multiple values in a column

佐手、 提交于 2021-02-04 19:54:22
问题 I have a table with approximately 3000 rows with data in the form of : Number Type 10001 0 10005 7 10006 0 10007 14 10012 16 10022 14 10023 0 10024 0 10029 7 10035 17 10045 14 I want to add a third column so that the table looks like : Number Type SCHEach 10001 0 0 10005 7 0 10006 0 0 10007 14 0 10012 16 1 10022 14 0 10023 0 0 10024 0 0 10029 7 0 10035 17 1 10045 14 0 where values in the SCHEach column are based on values in the Type column. If values in the Type column are 16,17,21, or 22,

How do I check whether a file or file directory exist in bash?

守給你的承諾、 提交于 2021-02-04 12:23:21
问题 I currently have this bash script (which is located in my home directory, i.e., /home/fusion809/ and I am running it as root as it's necessary for the icon copying lines): cd /home/fusion809/Pictures/Icon* declare -a A={Arch,Debian,Fedora,Mageia,Manjaro,OpenSUSE} declare -a B={Adwaita,Faenza,gnome,Humanity} for i in $A; do for j in $B; do if test -e /usr/share/icons/$j/scalable ; else mkdir /usr/share/icons/$j/scalable/ fi if test -e /usr/share/icons/$j/scalable/$i.svg ; else cp -a $i*.svg

How can I simplify repetitive if-elif statements in my grading system function?

◇◆丶佛笑我妖孽 提交于 2021-02-04 09:22:30
问题 The goal is to build a program to convert scores from a '0 to 1' system to an 'F to A' system: If score >= 0.9 would print 'A' If score >= 0.8 would print 'B' 0.7, C 0.6, D And any value below that point, print F This is the way to build it and it works on the program, but it's somewhat repetitive: if scr >= 0.9: print('A') elif scr >= 0.8: print('B') elif scr >= 0.7: print('C') elif scr >= 0.6: print('D') else: print('F') I would like to know if there is a way to build a function so that the

Google Sheets cell info

一笑奈何 提交于 2021-02-04 08:25:34
问题 I am doing a ledger for accounting purposes. I have it set up like a checkbook registry. It has 4 columns: Date, Description, Amount and Balance. The formula set up in the last column (Balance) is set up to add the number in the "Amount" column to the balance in the last line entry. The formula is copied down the page in the last column. What I would like to do, is only have a number in that column if there is an entry on that line. Here is my question: Is there a way to hide the number in

How to filter a list based on ascending values?

六月ゝ 毕业季﹏ 提交于 2021-02-04 07:29:21
问题 I have the following 3 lists: minimal_values = ['0,32', '0,35', '0,45'] maximal_values = ['0,78', '0,85', '0,72'] my_list = [ ['Morocco', 'Meat', '190,00', '0,15'], ['Morocco', 'Meat', '189,90', '0,32'], ['Morocco', 'Meat', '189,38', '0,44'], ['Morocco', 'Meat', '188,94', '0,60'], ['Morocco', 'Meat', '188,49', '0,78'], ['Morocco', 'Meat', '187,99', '0,70'], ['Spain', 'Meat', '190,76', '0,10'], ['Spain', 'Meat', '190,16', '0,20'], ['Spain', 'Meat', '189,56', '0,35'], ['Spain', 'Meat', '189,01'