LordMorgan LordMorgan - 2 months ago 7
Python Question

Why can python not assign an operator?

In my computer science controlled assessment it keeps coming up with an error. It says that it cannot assign an operator even though the user has given this a value in the earlier code. Can you explain in simple terms ?

import random
def Menu():
print ("Enter a number from 1-3 to select your choice")
Menuinput = str(input("1. Enter values\n 2. Save Data\n 3. Display disease percentage\n 4. Quit Program\n"))
return Menuinput

A=0
while A<1:
Menuinput = Menu()

if Menuinput == "1":

NumBirtRate = float(input("Enter birth rate of Greenflies e.g. 1.5 "))

while NumBirtRate < 0.1:
print ("This is not a valid option please enter another")
NumBirtRate = float(input("Enter birth rate of Greenflies e.g. 1.5 "))

NumSurvRate = float(input("Enter survival rate of Greenflies e.g. 0.5 "))

while NumSurvRate > 1:
print ("This is not a valid option please enter another")
NumSurvRate = float(input("Enter survival rate of Greenflies e.g. 0.5 "))

NumSen = float(input("Enter number of Senile Greenflies in thousands"))

NumAdu = float(input("Enter number of Adult Greenflies in thousands"))

NumJuv = float(input("Enter number of Juveniles Greenflies in thousands"))

NumGen = int(input("Enter number of Generations from 5 to 25"))

while NumGen > 25:
print ("This is not a valid option please enter another")
NumGen = int(input("Enter number of Generations from 5 to 25"))

while NumGen < 5:
print ("This is not a valid option please enter another")
NumGen = int(input("Enter number of Generations from 5 to 25"))

if NumGen == "1":
**This bit is the problem ->** NumAdu * NumBirthRate = Gen1Juv
NumJuv * NumSurvRate = Gen1Adu
NumAdu * NumSurvRate + NumSen * NumSurvRate = Gen1Sen

elif Menuinput == "2":
print ("Export data to file")

elif Menuinput == "3":
print ("Disease Trigger")
(random.randint(20,50),"%")


elif Menuinput == "4":
quit()

else:
print("This is not a valid option please select another")

Answer

Because you have your stuff backwards:

NumAdu * NumBirthRate = Gen1Juv

->

Gen1Juv = NumAdu * NumBirthRate

Assignment is "name on left" gets set to "value on right" (of the =). Trying to write that backwards is an error.

Comments