{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec6SelectionStrings

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

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern