Once again, this week I will ask you to work with a partner of your choice. You will turn in a SINGLE answer sheet for both partners. As a reminder, you should...
Failure to follow these guidelines may cause you to lose points for this activity.
Enter the following code into an editor in python.
Run this code.
[Q1] What happens?
Modify the previous code to look like this instead:
Run this code.
[Q2] How is the output from this code different than the output from the previous code?
We are going to play with creating a type of art today called ASCII art. This type of computer art consists of arranging printable characters on the screen in an artistic form. (Think of creating art and shapes on the screen before modern graphics cards.)
The first shape we make today is a simple row of stars.
Write a program that you will save in a file called starLine.py.
This program should:
Note: Your code needs to have the following line in it somewhere:
(This line will print one star at a time, followed by a space. It also allows the next print to start on the same line.)
Note 2: You cannot use string manipulation to get your stars -- you must practice looping and printing one star at a time in this lab. So, this mean I will not accept the following code in any activity or any permutation of this code where you use multiplication to print your stars:
Note 3: While you might be tempted to use a while loop, a for loop is actually easier in the long run....
Save this code as starLine.py and upload it into eLearning:
[SIG1] Please show starLine.py to an instructor BEFORE moving on
Modify your previous code to use nested loops so that it prints out mulitple lines of stars, which happen to look like a left-justified right triangle! Write a loop around your previous loop code to run it multiple times with different numbers of stars. Your code should prompt for a positive height, and re-prompt if a positive number was not entered.
Hint 1: The height is the number of times the outer loop should run.
Hint 2: The inner loop prints out one line of stars, starting with one star on the first line and incrementing the number of stars by one each time it runs.
Save this code as leftTriangle.py and upload it into eLearning:
[SIG2] Please show leftTriangle.py to an instructor BEFORE moving on
In Activity C, you printed out a left-justified right triangle. Now I want you to think about writing a right-justified right triangle! For example:
Each line is actually a mixture of spaces and stars.
[Q3] How does the height of the triangle relate to the number of spaces and stars printed the first line? On the second line?
Save this code as rightTriangle.py and upload it into eLearning:
[SIG3] Please show rightTriangle.py to an instructor.
Don't forget to hand in your answer sheet to the professor or TA before you leave!