Run update21, if you haven't already, to create cs21/labs/03. Then cd into your cs21/labs/03 directory and create the python programs for lab 3 in this directory (handin21 looks for your lab 3 assignments in your cs21/labs/03 directory):
$ update21 $ cd cs21/labs/03 $ pwd /home/your_user_name/cs21/labs/03
Your programs are graded on both correctness and style. Please review
the comments regarding programming style on the main page.
After grading your final exam results, I need to convert the number scores into letter grades. Let's assume I use the following scale to compute grades:
A: 93-100 B: 81-92 C: 72-80 D: 59-71 F: below 59
Write a program in a file named grades.py that takes as input a numeric score and prints out the letter grade equivalent. Here are some sample runs of a working program:
$ python grades.py This program computes a letter grade given a numeric score Enter the numeric score: 96 The letter grade equivalent is: A $ python grades.py This program computes a letter grade given a numeric score Enter the numeric score: 72 The letter grade equivalent is: C $ python grades.py This program computes a letter grade given a numeric score Enter the numeric score: 50 The letter grade equivalent is: F
A typical calendar year contains 365 days. Earth, however, takes slighly longer than 365 days to complete an orbit around the sun. To account for this difference in a calendar year and an astronomical year, we periodically add a day to a year on February 29. Years with this added day are called leap years.
Write a program called leapYear.py that takes as input a year and outputs whether that year is a leap year or not. A leap year typically occurs every 4 years (2004 and 108 for example, but not 1991). The exception is that years divisible by 100 must also be divisible by 400 to be leap years. That is, a year divisilble by 100 is not a leap year unless it is also divisible by 400. For example, 1700, 1800, and 1900 are not leap years but 2000 is a leap year.
Hint:
$ python leapYear.py This program calculates if a provided year is a leap year. Enter a year: 2011 2011 is NOT a leap year $ python leapYear.py This program calculates if a provided year is a leap year. Enter a year: 1908 1908 IS a leap year $ python leapYear.py This program calculates if a provided year is a leap year. Enter a year: 2100 2100 is NOT a leap year
$ python prime.py This program calculates if a number is prime. Enter a number: 5 5 is a prime number $ python prime.py This program calculates if a number is prime. Enter a number: 10 10 is not a prime number
$ python pattern.py This program prints out two different patterns of chars. Enter a character: $ Enter a value for the size of the pyramid of chars: 10 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Enter a value for the size of the diamond: 4 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ python pattern.py This program prints out two different patterns of chars. Enter a character: * Enter a value for the size of the pyramid of chars: 6 * * * * * * * * * * * * * * * * * * * * * Enter a value for the size of the diamond: 9 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Note: there is one space between the characters in these patterns
$ python findPrimes.py
This program prints out all primes from 1 to 1000.
Prime numbers:
1
2
3
5
and so on.
Write a program that takes as input the size of the pattern to print, and prints the following box of stars:
$ python starbox.py This program prints out a box of stars Enter a value for the size of the box: 8 * * * * * * * * | * * * * * * * * * * * * * * * ## | ## * * * * * * * * * * * * * #### | #### * * * * * * * * * * * ###### | ###### * * * * * * * * * ######## | ######## * * * * * * * ########## | ########## * * * * * ############ | ############ * * * ############## | ############## * * ############## | ############## * * * ############ | ############ * * * * * ########## | ########## * * * * * * * ######## | ######## * * * * * * * * * ###### | ###### * * * * * * * * * * * #### | #### * * * * * * * * * * * * * ## | ## * * * * * * * * * * * * * * * | * * * * * * * * $ python starbox.py This program prints out a box of stars Enter a value for the size of the box: 5 * * * * * | * * * * * * * * * ## | ## * * * * * * * #### | #### * * * * * ###### | ###### * * * ######## | ######## * * ######## | ######## * * * ###### | ###### * * * * * #### | #### * * * * * * * ## | ## * * * * * * * * * | * * * * *