Lab 3: Math and Strings in Python
Points Possible: 100
Due: Thursday, September 19th
In this lab, we will practice the concepts learned in week three. We will use math module functions, string functions, and Python programming to solve the problems.
Submission:
- Submit a Python file for each of the four programs.
Pair programming
Pair programming is a software development technique in which two programmers work together at one computer. One, the driver, writes code while the other, the navigator, reviews each line of code as it is typed in. The two programmers switch roles frequently.
- This is a group assignment, but you should each turn in your code individually.
- Groups will be assigned at the beginning of lab.
- Rules for groups work:
- Do not divide and conquer, i.e., do not assign each person an exercise to work on individually.
- Work together on each exercise and share responsibilities, each person should have a chance to write code.
Program 1: Math and Strings
Write a program that prints the results of the following:
- $sin(2 \pi)$ (you can use
math.pi
) - $log(16)$ (use natural log)
round(-12.5)
-
string_val="Introduction to Computing." string_val[:-1]
-
string_val="Introduction to Computing." string_val[2:]
Save the program is math_and_strings.py
and attach it to the Blackboard lab assignment.
Program 2: Compute Interest
Write a program that reads the values of total amount and interest rate. Then prints the value of the interest amount. Please display the result up to 2 decimal places.
Use the formula:
\[interestAmount = totalAmount * interestRate\]Save the program is interest.py
and attach it to the Blackboard lab assignment.
Program 3: Math Library
Using math library functions, write a program that reads the value of 2 numbers a
, b
and solve the following equations:
Please display the results up to 2 decimal places. Please use math.log
function for natural log.
Save the program is library.py
and attach it to the Blackboard lab assignment.
Program 4: Grade Count
Suppose the text below indicates the grades of students and the text is stored in a variable, compute the total count of students who got “Grade-A”, “Grade-B” and “Grade-C” and display the counts. Hint: You can use the count
function.
string_val = “User1:Grade-A, User2:Grade-B, User3:Grade-C, User4:Grade-A, User5:Grade-B, User6: Grade-A, User7: Grade-C, User8: Grade-B, User9:Grade-A, User10: Grade-A, User11: Grade-C, User12: Grade-A, User13: Grade-B, User14: Grade-C, User15: Grade-A”
Save the program is grades.py
and attach it to the Blackboard lab assignment.
- Starter code here grades.py
Grading Rubric for the programs:
Grading | Points Possible |
Appropriate header and comments | 5 |
Input | 5 |
Computation | 10 |
Print output | 5 |
TOTAL 25 points for each program