In: Computer Science
Python Chemicals can be described as either acids or bases. The pH scale measures the concentration of hydrogen ions in a chemical to determine just how acidic or basic it is. For this task you are going to determine whether a chemical is acidic or basic based on its pH value, and how strongly it has that property. Remember, don't call input() or print() anywhere, just use the parameters provided and return statements.
You must have at least one conditional in each function. You cannot import any module. A couple of the tasks have individual restrictions; note them, as we will remove points for any task that does not follow the requirements.
def chemical_strength(pH): Accepts one floating point parameter for the pH value, and then:
Determines if the pH value is valid (pH must be between 0 and 14 inclusive).
You’ll return the string "bad measurement" if pH value doesn't make sense.
Determines a description of the chemical based on its pH value.
o A pH of less than 7 is an acidic chemical, however, we will be more specific:
▪ a pH value less than or equal to 1 is a "very strong
acid"
▪ a pH value between 1 and 4 (exclusive) is a "strong acid"
▪ a pH value of exactly 4 is a "plain acid"
▪ a pH between 4 and 6 (exclusive) is a "weak acid"
▪ a pH value greater than or equal to 6 is a "very weak
acid"
o A pH of more than 7 is a basic chemical, however, we will be more
specific:
▪ a pH value less than or equal to 8 is a "very weak base"
▪ a pH value between 8 and 10 (exclusive) is a "weak base"
▪ a pH value of exactly 10 is a "plain base"
▪ a pH value between 10 and 13 (exclusive) is a "strong base"▪ a pH
value greater than or equal to 13 is a "very strong base"
o If the pH is exactly 7, the chemical is simply "neutral"
Returns the strength description as a string, e.g. "weak acid", "very strong base" etc.• Examples:
o #pH is in between 4 and 6
chem_strength(4.7) → 'weak acid'
o # pH is outside of the valid pH range chem_strength(15.43) → 'bad measurement'
#source code:
def chemical_strength(pH): #here no print function is used
if(pH>=0 and pH<=14):
if(pH<7):
if(pH<=1):
return "very strong acid"
elif(pH>1 and
pH<4):
return "strong acid"
elif(pH==4):
return "plain acid"
elif(pH>4 and
pH<6):
return "weak acid"
elif(pH>=6):
return "very weak acid"
elif(pH>7):
if(pH<=8):
return "very weak base"
elif(pH>8 and
pH<10):
return "weak base"
elif(pH==10):
return "plain base"
elif(pH>10
and pH<13):
return "strong base"
elif(pH>=13):
return "very strong base"
elif(pH==7):
return
'''"neutral","weak acid", "very strong base"'''
else:
return "bad
measurement"
print(chemical_strength(4.7)) #display for output
print(chemical_strength(15.43)) #display for output thats why here
used print function
#source code in image format:
#output:
#if you have any doubts comment below...if you like give thumbs up....