Lec8Strings2

# Lec8Strings2 - Given a score, print out the grade. We want...

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

Given a score, print out the grade. We want to print out A+, A-, B+, B, B-, … Two jobs: Figure out the letter grade Figure out + or – 71 81 91 What do we use to determine + vs -? Only the ones place What do we use to determine the A vs B? The tens place So far, score was fp from 0->1. What I want is an integer from 0->100. intScore = int(score*100) tens = intScore // 10 ones = intScore % 10 The other popular use of modulus (%) – when you want an answer in the range 0->n-1, and if it is larger than n-1, you want it wrap around. Hint: this might be useful for lab on Friday. Choices: if if-else if-else if-else if-else Our case: We want to always pick one of five choices if (tens >= 9): print(“A”) elif (tens == 8): print(“B”) elif (tens == 7): print(“C”) elif (tens == 6): print(“D”) else: print(“F”) Either way to: print + print – do nothing if (ones >= 7): print(“+”) elif (ones < 3): print(“-“) # don’t put any else – this means “else do nothing” input output 0 0 1 1 2 2 3 3 4 4 5 5 6 0 7 1 8 2 9 3 10 4

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.

## Lec8Strings2 - Given a score, print out the grade. We want...

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

View Full Document
Ask a homework question - tutors are online