{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec6SelectionStrings

Lec6SelectionStrings - You want to translate a score(from...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
You want to translate a score (from 0 -> 1) into a grade (A-F) if score >= 0.9: Print(“A”) if (score < 0.9) and (score >= 0.8): # works in python, Java, C, C++, Print(“B”) if 0.7 <= score < 0.8: # python shortcut Print(“C”) if (score < 0.7) and (score >= 0.6): Print(“D”) if (score < 0.6): Print(“F”); Nested statements if (score >= 0.8): if (score >= 0.9): print(“A”) else: print(“B”) else: # score < 0.8 if (score >= 0.7): print(“C”) else: if (score >= 0.6): print(“D”) else: print(“F”) We have many choices, but only one that we want to execute if-else if-else if-… -[else] if score >= 0.9: Print(“A”) # elif – only do the elif if the prior if or # elif was false elif (score >= 0.8): Print(“B”) elif score >= 0.7: # python shortcut Print(“C”) elif score >= 0.6): Print(“D”) else: Print(“F”); The above only works if I only want 1 of the above to happen What if, instead, you want to choose between the first two, and then allow the third to happen even if one of the first two was true if score >= 0.9: Print(“A”) # elif – only do the elif if the prior if or # elif was false elif (score >= 0.8): Print(“B”)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern