简体   繁体   中英

Python : redefining the value of a variable by conditions

Beta = (math.pi)/2 + (math.pi)/20 - Theta

I would love that the variable Beta once calculated receives another value by the following conditions but it seems to have no effect.

if Beta < (math.pi)/10:
    Beta == 1

if (math.pi)/10 < Beta < 2*(math.pi)/10:
    Beta == 2

if 2*(math.pi)/10 < Beta < 3*(math.pi)/10:
    Beta == 3 

if (n-1)*(math.pi)/10 < Beta < n*(math.pi)/10:
    Beta == n

You mixed == operator with = , the first is equality test and the second is assignment operator. Replace all == with = and that will work.

just change the Beta == 1/ Beta == 2/ Beta == 3 / Beta == n

to Beta = 1 , with one equal sign , since double equal sign represent condition and not assignment.

Change the code to include = sign instead of ==

== sign represents equality check in Python whereas = sign is an assignment sign.

Try the following:

Beta = (math.pi)/2 + (math.pi)/20 - Theta

if Beta < (math.pi)/10:
    Beta = 1

if (math.pi)/10 < Beta < 2*(math.pi)/10:
    Beta = 2

if 2*(math.pi)/10 < Beta < 3*(math.pi)/10:
    Beta = 3 

if (n-1)*(math.pi)/10 < Beta < n*(math.pi)/10:
    Beta = n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM