In: Computer Science
How do I get the following code to accept a float input, while also fixing the syntax errors in the code because I can't figure out what is wrong with it.
def chemical_strength(pH):
if 0<pH>14:
if pH <= 7:
if pH = 7:
ans = str("neutral")
else: # ph < 7
if 0<pH>=1:
ans = str("very strong acid")
else: # 1<pH>7
if 1<pH>4:
ans = str("strong acid")
else: # 4=<ph>7
if pH = 4:
ans = str("plain acid")
else: # 4<pH>7
if 4<pH>6:
ans = str("weak acid")
else: # 6=<pH>7
ans = str("very weak acid")
else pH >= 7:
if pH = 7:
ans = str("neutral")
else: # ph > 7
if 7<pH>=8:
ans = str("very weak base")
else: # 8<pH>14
if 8<pH>10:
ans = str("weak base")
else: # 10=<pH>14
if pH = 10:
ans = str("plain base")
else: # 10<pH>14
if 10<pH>13:
ans = str("strong base")
else: # 13=<pH>14
ans = str("very strong base")
else:
ans = str("bad measurement")
return ans
If you have any doubts, please give me comment...
def chemical_strength(pH):
if 0<pH<14:
if pH == 7:
ans = str("neutral")
elif pH < 7:
if 0<pH<=1:
ans = str("very strong acid")
else: # 1<pH<7
if 1<pH>4:
ans = str("strong acid")
else: # 4=<ph<7
if pH == 4:
ans = str("plain acid")
else: # 4<pH>7
if 4<pH<6:
ans = str("weak acid")
else: # 6=<pH>7
ans = str("very weak acid")
else:
if 7<pH<=8:
ans = str("very weak base")
else: # 8<pH<14
if 8<pH<10:
ans = str("weak base")
else: # 10=<pH<14
if pH == 10:
ans = str("plain base")
else: # 10<pH>14
if 10<pH<13:
ans = str("strong base")
else: # 13=<pH>14
ans = str("very strong base")
else:
ans = str("bad measurement")
return ans
pH = float(input("Enter pH value: "))
print(chemical_strength(pH))