Lec6SelectionStrings

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 8 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online