Question

In: Computer Science

How do I get the following code to accept a float input, while also fixing the...

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

Solutions

Expert Solution

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))


Related Solutions

HOW DO I ADD ON TO THIS CODE SO THAT IT DISPLAYS ALL THE VALUES INPUT...
HOW DO I ADD ON TO THIS CODE SO THAT IT DISPLAYS ALL THE VALUES INPUT BY THE USER AS SPECIFIED IN THEH FIRST PART OF THE QUESTION? Ask the user to enter a number and display the number, followed by ***, followed by the number squared, followed by &&&, and followed by the number cubed. Allow the user to enter as many numbers as he/she wishes. So, use a reasonable sentinel value to end the loop (for example, -999)....
How do I add the information below to my current code that I have also posted...
How do I add the information below to my current code that I have also posted below. <!DOCTYPE html> <html> <!-- The author of this code is: Ikeem Mays --> <body> <header> <h1> My Grocery Site </h1> </header> <article> This is web content about a grocery store that might be in any town. The store stocks fresh produce, as well as essential grocery items. Below are category lists of products you can find in the grocery store. </article> <div class...
How do I get the first initial of a first, middle, and last name? Also when...
How do I get the first initial of a first, middle, and last name? Also when I look to count characters in the name I want to be abel to count the spaces in-between the names how can i do this?
Java question - How can the code below be modified to accept multi digit input. String...
Java question - How can the code below be modified to accept multi digit input. String e = "1+9+8"; int r = e.charAt(0)-'0'; for (int i = 1; i < e.length(); i+=2){    if (e.charAt(i) == '+'){ r += e.charAt(i+1)-'0'; } else{ r -= e.charAt(i+1)-'0'; } The only built in String methods that can be used are lowercase(), length(), and charAt(). Arrays and parseInt() cannot be used. So we want to know how we can get an answer if a...
How do i get the code below to add an element before another without making the...
How do i get the code below to add an element before another without making the array off one element? (javascript) public void addBefore(double element) { itemCount++; double data[] = new double[this.data.length]; if(currentIndex <= itemCount) { if(currentIndex != 0) { for(int index = currentIndex; index >= itemCount; index ++) { data[index] = this.data[index]; } currentIndex--; data[currentIndex] = element; } if(currentIndex == 0) { data[0] = element; currentIndex = 0; } } }
What can be done to get “smear” to dry more quickly before heat fixing. Also, please...
What can be done to get “smear” to dry more quickly before heat fixing. Also, please identify two things that you should decidedly not do to get to speeey up the air drying
Determine the output of the following pseudo-code. Also, explain how did you get this output. fun(int...
Determine the output of the following pseudo-code. Also, explain how did you get this output. fun(int n){ if (n==1) then return; println(n); if (n%2=0) then fun(n/2); else fun(3*n + 1); } Main(){ fun(14); }
Hello, In C++ how would I get it to ignore a percent sign in an input....
Hello, In C++ how would I get it to ignore a percent sign in an input. cout << "Enter the annual interest rate in %: "; cin >> interestRate; I want the user to input "3%" for example but having the % sign makes the program terminate. How can I get it to just read 3% (or any percent number) as just "3"
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
what is the solution of this code? Also how would I run it in python to...
what is the solution of this code? Also how would I run it in python to check? q = Queue() q.enqueue(10) q.enqueue(12) q.enqueue(15) for i in range(len(q)): → if len(q) % 2 == 0: → → q.enqueue(q.dequeue()) → else: → → q.dequeue() print(q)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT