#Name: Thomas Hunter #Email: thomas.hunter1870@myhunter.cuny.edu #Date: September 1, 2024 #This program prints: Hello, World! print("Hello, World!")
Submit the following programs via Gradescope:
Write a program that prints "Hello, World!" to the screen.
Write a program that draws an Octagon using the turtle library.
Note: Whenever submitting a turtle program, choose a name for your file that is not turtle.py.
When executing the "import turtle" statement, the computer first looks in the folder where the file is saved for the turtle module and then in the libraries (and other places on the path). So, it thinks the module is itself, causing all kinds of errors. To avoid this, name your program something like "myTurtle.py" or "program2.py".
Write a program that implements the pseudocode ("informal high-level description of the operating principle of a computer program or other algorithm") below:
Repeat 36 times:
Walk forward 100 steps
Turn left 145 degrees
Walk forward 10 steps
Turn right 90 degrees
Walk forward 10 steps
Turn left 135 degrees
Walk forward 100 steps
The result should look as follows:
Write a program that will print "I love Python!" 25 times.
The output of your program should be:
I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python! I love Python!
Write a program that uses the turtle library to draw a 5-pointed star.
Your output should look like this:
Hint: To draw the 5-pointed star, the turtle must turn a total of 720 degrees. How many degrees does the turtle need to turn at each point?
Write a program that prints out the numbers from 2 to 17.
The output of your program should be:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Using the string commands introduced in Lab 2, write a Python program that prompts the user for a message, and then prints the message, the message in upper case letters, and the message in lower case letters.
A sample run of your program should look like:
Enter a message: Mihi cura futuri Mihi cura futuri MIHI CURA FUTURI mihi cura futuri
Another run:
Enter a message: I love Python! I love Python! I LOVE PYTHON! i love python!
Hint: Your program should be able to take any phrase the user enters and prints it, it in upper case letters, and it in lower case letters. To do that, you need to store the phrase in a variable and print variations of the stored variable.
Write a program that prompts the user to enter a phrase and then prints out the ASCII code of each character in the phrase.
A sample run of your program should look like:
Enter a phrase: I love Python! In ASCII: 73 32 108 111 118 101 32 80 121 116 104 111 110 33
And another sample run:
Enter a phrase: ABC In ASCII: 65 66 67
Hint: If c is a character, ord(c) returns its ASCII code. For example, if c is 'I', then ord(c) returns 73. See Lab 2.
Write a program that asks the user for the hexcode of a color and then displays a turtle that color.
Make sure the turtle is the correct shape by including turtle.shape("turtle") in your program.
A sample run of your program should look like:
Enter a hex string: #A922A9
and the output should look similar to:
Write a program that implements the pseudocode below:
For i = 5, 10, 15, 20, 25, ... ,300: Walk forward i steps Turn left 91 degreesYour output should look similar to:
Hint: See examples of range(start,stop,step) in Lab 2.
Modify the program from Lab 3 to show the shades of blue.
Your output should look similar to:
Draw a cornflower blue pentagon using the turtle library. You can specify the color by name ("cornflowerblue"), by hex string ("#6495ED"), or by 255-mode values (100, 149, 237). The turtle should be turtle shaped. Your turtle should move forward 100 units, turn left the correct amount of degrees, and then stamp.
A sample run of your program will look like:
Hint: See Lab 3.
Write a program that asks the user for a message, then prints out that message in reverse. The reversed output message should be printed with two copies of each character per line.
A sample run of your program should look like:
Enter a message: I love Python! ! ! n n o o h h t t y y P P e e v v o o l l I I
Hint: use a for-loop that starts at the last index in the string and stops at the first index in the string:
lastIdx = len(myString) - 1 for i in range(lastIdx, -1, -1): #print each character in myString, twice on each line
Write a program that asks the user for 5 whole (integer) numbers. For each number, turn the turtle left the degrees entered and then the turtle should move forward 100.
A sample run of your program should look like:
Enter a number: 270 Enter a number: 100 Enter a number: 190 Enter a number: 200 Enter a number: 80
and the output should look similar to:
(The cipher disk above shifts 'A' to 'N', 'B' to 'O', ... 'Z' to 'M', or a shift of 13. From secretcodebreaker.com.)
Write a program that prompts the user to enter a word and then prints out the word with each letter shifted right by 13. That is, 'a' becomes 'n', 'b' becomes 'o', ... 'y' becomes 'l', and 'z' becomes 'm'.
Assume that all inputted words are in lower case letters: 'a',...,'z'.
A sample run of your program should look like:
Enter a word: zebra Your word in code is: mroen
Hint: You can use this file to get started with this assignment.
Write a program that converts kilometers to miles. Your program should prompt the user for the number of kilometers and then print out the number of miles.
A useful formula: miles = 0.621371*kilometers.
Write a program that implements the pseudocode below:
1. Ask the user for the number of hours until the weekend. 2. Print out the days until the weekend (days = hours // 24) 3. Print out the leftover hours (leftover = hours % 24)
A sample run of your program should look like:
Enter number of hours: 27 Days: 1 Hours: 3
and another sample run:
Enter number of hours: 52 Days: 2 Hours: 4
Hint: See Section 2.7.
Following Lab 5, write a program that asks the user for the name of a png file and print the number of pixels that are nearly white (the fraction of red, the fraction of green, and the fraction of blue are all above 0.75).
For example, if your file was of the snow pack in the Sierra Nevada mountains in California in September 2014:
then a sample run would be:
Enter file name: caDrought2014.png Snow count is 38010
Note: for this program, you only need to compute the snow count. Showing the image will confuse the grading script, since it's only expecting the snow count.
We can store DNA sequences as strings. These strings are made up of the letters A, C, G, and T. For a given DNA string, the GC-content is the percent of the string that is C or G, written as a decimal.
Write a program that prompts the user for a DNA string, and then prints the length and GC-content of that string.
A sample run of the program:
Enter a DNA string: ACGCCCGGGATG Length is 12 GC-content is 0.75
Hint: You can use a for-loop to go through each character in the string, and count each time you encounter a 'C' or 'G'. You can use an if-statment to check what kind of character the loop is currently on. Alternatively, you can use the count() method introduced in Lab 2 to get the total occurrences of 'C' and 'G' in the string.
Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.
Build a circuit that has the same behavior as a nor gate (i.e. for the same inputs, gives identical output) using only and, or, and not gates.
Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.
Write a logical expression that is equivalent to the circuit that computes the majority of 3 inputs, called in1, in2, in3:
Save your expression to a text file. See Lab 5 for the format for submitting logical expressions to Gradescope.
Logical gates can be used to do arithmetic on binary numbers. For example, we can write a logical circuit whose output is one more than the inputted number. Our inputs are in1 and in2 and the outputs are stored in out1, out2, and out3.
Here is a table of the inputs and outputs:
Inputs | Outputs | |||||
---|---|---|---|---|---|---|
Decimal Number | in1 | in2 | Decimal Number | out1 | out2 | out3 |
0 | 0 | 0 | 1 | 0 | 0 | 1 |
1 | 0 | 1 | 2 | 0 | 1 | 0 |
2 | 1 | 0 | 3 | 0 | 1 | 1 |
3 | 1 | 1 | 4 | 1 | 0 | 0 |
Submit a text file with each of the outputs on a separate line:
#Name: YourNameHere #Date: October 2024 #Logical expressions for a 4-bit incrementer out1 = ... out2 = ... out3 = ...Where "..." is replaced by your logical expression (see Lab 5).
Note: here's a quick review of binary numbers.
The program turtleString.py takes a string as input and uses that string to control what the turtle draws on the screen (inspired by code.org's graph paper programming). Currently, the program processes the following commands:
Modify this program to allow the user also to specify with the following symbols:
In Lab 6, you created a GitHub account. Submit a text file with the name of your account. The grading script is expecting a file with the format:
#Name: Your name #Date: October 2024 #Account name for my GitHub account AccountNameGoesHere
Note: it takes a few minutes for a newly created GitHub account to be visible. If you submit to Gradescope and get a message that the account doesn't exist, wait a few minutes and try again.
Write a program that asks the user for a name of an image .png file and the name of an output file. Your program should create a new image that has only the blue channel of the original image (that is, no green channel).
A sample run of your program should look like:
Enter name of the input file: csBridge.png Enter name of the output file: blueH.png
Sample input and resulting output files:
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show() and plt.imshow() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Write a program that implements the pseudocode below:
For i = 90, 88, 86, 84, 82, ... ,0: Walk forward 25 steps Turn left i degrees
Your output should look similar to:
Write a program that creates a 'C' logo for CUNY on a 30x30 grid.
The grading script is expecting:
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show() and plt.imshow() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Modify the flood map of NYC from Lab 4 to color the region of the map with elevation greater than 6 feet and less than or equal 20 feet above sea level the color grey (50% red, 50% green, and 50% blue).
Your resulting map should look like:
and be saved to a file called floodMap.png.
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show() and plt.show() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Write a program that computes the minimum, average, and maximum population over time for a borough (entered by the user). Your program should assume that the NYC historical population data file, nycHistPop.csv is in the same directory.
A sample run of your program:
Enter borough: Staten Island Minimum population: 727 Average population: 139814.23076923078 Maximum population: 474558
and another run:
Enter borough: Brooklyn Minimum population: 2017 Average population: 1252437.5384615385 Maximum population: 2738175
Hint: See Lab 6.
Write a program that prompts the user to enter a list of names. Each person's name is separated from the next by a semi-colon and a space ('; ') and the names are entered lastName, firstName (i.e. separated by ', '). Your program should then print out the names, one per line, with the first initial of the first name, followed by ".", and followed by the last name.
A sample run of your program should look like:
Please enter your list of names: Cohn, Mildred; Dolciani, Mary P.; Rees, Mina; Teitelbaum, Ruth; Yalow, Rosalyn You entered: M. Cohn M. Dolciani M. Rees R. Teitelbaum R. Yalow Thank you for using my name organizer!
Hint: Do this problem in parts: first, split the list by person (what should the delimiter be?). Then, split each of person's name into first and last name (what should the delimiter be here?). If you have a string str, what is s = str[0] + "."?
Modify the map-mapking program from Lab 4 to create a topographic map (highlighting the points that have elevations that are multiples of 10). Your program should ask the user for the amount of blue (a floating point number between 0.0 and 1.0), the name of the output imagee, create a new image with thaht name and with the pixels colored as follows:
A sample run of your program should look like:
How blue is the ocean: 0.5 What is the output file: medBlue.png Thank you for using my program! Your map is stored medBlue.png.
Your resulting map should look like:
and be saved to a file called medBlue.png.
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show() and plt.imshow() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Modify the program from Lab 6 that displays the NYC historical population data. Your program should ask the user for the borough, an name for the output file, and then display the fraction of the population that has lived in that borough, over time.
A sample run of the program:
Enter borough name: Queens Enter output file name: qFraction.png
The file qFraction.png:
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show() and plt.imshow() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
Write a program that implements the pseudocode below:
1. Ask the user for the number of seconds until lecture starts. 2. Print out the hours until lecture (hours = seconds //3600). 3. Compute the remaining seconds (rem = seconds % 3600). 4. Print out the minutes until lecture (minutes = rem // 60). 5. Print out the remaining seconds (remSec = rem % 60).
A sample run of your program should look like:
Enter number of seconds: 62 Hours: 0 Minutes: 1 Seconds: 2
and another sample run:
Enter number of seconds: 4000 Hours: 1 Minutes: 6 Seconds: 40
Write a Bash script that prints Hello, World to the screen.
Submit a single text file containing your Unix shell commands. See Lab 6 for details.