Ok i wrote this in python then rewrote because i don’t like if else statements. the first version worked perfectly. my second one failed and ended up taking more lines than my first version. my question is, am i just stupid? is there a better way to do this or should i just accept the need for if else statement?
Tag: if-statement
If the integer pointed to by num begins with or contains 3
If the integer pointed to by num begins with or contains 3 please tell me how to code this Answer You can try converting the number to a string and then check, like this
How to write a for-loop/if-statement for a dataframe (integer) column
I have a dataframe with a column of integers that symbolise birthyears. Each row has 20xx or 19xx in it but some rows have only the xx part. What I wanna do is add 19 in front of those numbers with only 2 “elemets” if the integer is bigger than 22(starting from 0), or/and add 20 infront of those that
How do I order lines to be correct?
question is to arrange lines in order and with correct indent. I can’t write anything just need to arrange it. question is in the picture. what’s wrong with my answercapture Answer Try this:
Why my for loop is not iterating all the values
When I run this code and give input as 25 it should return me its not a prime num, But when I debug the code the range values are not iterating into if condition, only the first value of the range is passed and if its not == 0 it moves to the else part. Please help me why its
python for loop with if statement to divide numbers
if statement and for loop I am stuck with the following code, I have a column in which I want to divide by 2 if the number is above 10 and run this for all the rows. I have tried this code but it gives the error of the series is ambiguous: I suppose that I need a for loop
I have a problem with if statement and numbers
my problem is I want to make the elif statement work on numbers only but the elif statement work on any datatype, is there any way i can separate the numbers in string type from the other data types The Code OutPut Answer You can use and for this: Note that you can use in to check if a key
Printing two values of one variable under different conditions
Please consider the statements below: sum_value = fixed_value – current_value, where fixed_value is a constant, and current_value is a function of thresholds; thresholds has two threshold_level values: thresholds = [10, 20]; I need to find a rato of sim_value corresponding to threshold_level = 10 to sim_value corresponding to threshold_level = 20, that is final_sim_value = sim_value_at_10/sim_value_at_20. The code part is
In the IDLE shell 3.10.2 I am trying to write a series of if statements and it will not let me
I am new to Python but am following along a book closely. I can’t figure out why this won’t work. When I click return to write a new line below the second “if” statement, the code attempts to run and says invalid syntax, highlighting the second “if” Image of my code Answer The interactive window of IDLE knows that a
pdfplumber | Extract text from dynamic column layouts
Attempted Solution at bottom of post. I have near-working code that extracts the sentence containing a phrase, across multiple lines. However, some pages have columns. So respective outputs are incorrect; where separate texts are wrongly merged together as a bad sentence. This problem has been addressed in the following posts: Solution 1 Solution 2 Question: How do I “if-condition” whether