operators

Python: mathematical operations

Python: mathematical operations Question: I want to creat a programa that reads two input numbers and do mathematical operations on them: addition, multiplication, division and subtraction. I have this code: sum=0 multi=0 div=0 sub=0 for i in range(1,3): num = int(input(f'{i}º dígito: ‘)) sum+=num multi*=num div/=num sub-=num print(f’Soma: {sum}’) print(f’Multi: {multi}’) print(f’Div: {div}’) print(f’Sub: {sub}’) …

Total answers: 4

Why is it that I "cannot use assignment expressions with comparison" in Python?

Why is it that I "cannot use assignment expressions with comparison" in Python? Question: In the examples below x is assigned using the walrus operator and is then printed. mystring = "hello, world" #if 1 if x := mystring == "hello, world": print(x) #if 2 if x := (mystring == "hello, world"): print(x) #if 3 …

Total answers: 1

How to check all the conditions with 1 AND operator

How to check all the conditions with 1 AND operator Question: I want to check 2 conditions with just 1 AND operator. I tried the following: JavaScript: a = True b = False x = 3 if (x == 2 & a == true | b == false){ return; } With adjusted parentheses: a = …

Total answers: 2

How to use tkinter to bind operators like +-*/?

How to use tkinter to bind operators like +-*/? Question: i want to use bind in tkinter to detect if +-*/ is pressed. Is this possible? i’ve checked a lot on the internet and here is the code,i want to know what should i filed in the ??? import tkinter as tk class Application(tk.Tk): def …

Total answers: 1

A short python program

A short python program Question: I am new to learning python and need to write two lines of code to get the result using comparison operators and not if blocks. Help would be greatly appreciated, thanks. Using one of the comparison operators in Python, write a simple two-line program that takes the parameter n as …

Total answers: 2

python – weird results with exponent operator in idle

python – weird results with exponent operator in idle Question: I’m getting a strange result when squaring -1 in idle. What’s going on? Unexpected result: >>>| -1 ** 2 >>>| -1 Expected result: >>>| pow(-1,2) >>>| 1 >>>| my_var = -1 >>>| my_var **= 2 >>>| my_var >>>| 1 Asked By: user1026169 || Source Answers: …

Total answers: 2

Compare string and integer in same if statement

Compare string and integer in same if statement Question: I have a program that takes input from the user. I want to display an invalid option message if the input is a string or it is not a number between 1 to 4. I want to check all these 3 conditions in a single if …

Total answers: 3

Using .loc and OR operator returning ValueError

Using .loc and OR operator returning ValueError Question: I am trying to search for specific values in either of two columns and when a target value is found, change the number in a third column from positive to negative or negative to positive. te1 = df.loc[df[‘Transaction Event’] == ‘Exercise’] te2 = df.loc[df[‘Transaction Event’] == ‘Assignment’] …

Total answers: 1

How >> operator defines task dependencies in Airflow?

How >> operator defines task dependencies in Airflow? Question: I was going through Apache Airflow tutorial https://github.com/hgrif/airflow-tutorial and encountered this section for defining task dependencies. with DAG(‘airflow_tutorial_v01′, default_args=default_args, schedule_interval=’0 * * * *’, ) as dag: print_hello = BashOperator(task_id=’print_hello’, bash_command=’echo “hello”‘) sleep = BashOperator(task_id=’sleep’, bash_command=’sleep 5′) print_world = PythonOperator(task_id=’print_world’, python_callable=print_world) print_hello >> sleep >> print_world …

Total answers: 1

Blender Python add operator to menu with invoke_default

Blender Python add operator to menu with invoke_default Question: I have created a simple menu in python where i can add operators to it like that layout.operator("wm.center_object") layout.operator("wm.move_camera") the problem is that I need an operator to be called with INVOKE_DEFAULT. The following is the line to call it immediately: bpy.ops.object.custom_draw(‘INVOKE_DEFAULT’) and that works, but …

Total answers: 1