CSc 250: Lab 1 – Strings and Print

In this section, you are primarily going to be working with strings.

Before doing these problems (and any of the homeworks in this class) you’ll need to download and install python 3 and the wing101 python code editor. If you have not done so yet, go ahead and do it now!

Problem 1 (Warm-up)

Create a new python program file and name it lyrics.py. This program will print out the chorus to "straighten up and fly right" three times:
Straighten up and fly right
Straighten up and stay right
Straighten up and fly right
Cool down papa don't you blow your top

Straighten up and fly right
Straighten up and stay right
Straighten up and fly right
Cool down papa don't you blow your top

Straighten up and fly right
Straighten up and stay right
Straighten up and fly right
Cool down papa don't you blow your top
First, just write a program that prints out these lyrics exactly. No need to worry about eliminating redundancy for now.


Problem 2

Create a new python program file and name it lyrics-2.py. In this program, we'll print the same lyrics as the last problem, but attempt to eliminate some redundancy. Like we talked about in class, it is good to eliminate redundancy when possible. This time around, you should only use the following strings when printing out the lyrics:
straight = "Straighten up and"
fly = "fly"
stay = "stay"
right = "right"
cool = "Cool down papa don't you blow your top"
Try to use as few lines of code as possible!


Problem 3

Create a new python program file and name it move-info.py. This program should start by declaring the following few variables:
title           = "Star Wars"
year_released   = "1977"
lead_actor      = "Mark Hamill"
secondary_actor = "Harrison Ford"
description     = "Planets, Space-ships, Lightsabers, Oh My!"
Feel free to change these variables to different values for a differnt movie-of-choice. After declaring these variables in your script, should write some code that prints out a movie summary that looks like the following:
"Star Wars" was released in 1977.
The lead actor was Mark Hamill and the secondary actor was Harrison Ford.
The movie is about: Planets, Space-ships, Lightsabers, Oh My!
You should not hard-code the values into the string(s) that you are printing. The calls to `print()` should use the variables in the printout, and covert the variables to strings where necessary. This will require using string concatenation.


Problem 4

Create a new python program file and name it tree.py. This program should start by declaring the following few variables:
SPACE  = " "
LEAF  = "^"
TRUNK = "X"
Using ONLY these variables and string concatenation (+) and multiplication (*) you should write a sereis of prints that produced the following tree:
       ^
      ^^^
     ^^^^^
    ^^^^^^^
   ^^^^^^^^^
     ^^^^^
    ^^^^^^^
   ^^^^^^^^^
  ^^^^^^^^^^^
 ^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
      XXX
      XXX


Problem 5

Create a new python program file and name it tower.py. This program will print out a tower resembling the following:
    /\
    <>
   /~~\
  /~~~~\
 /~~~~~~\
 |[][][]|
 |[][][]|
 |[][][]|
 |[][][]|
 |[][][]|
 |[|--|]|
 |[|  |]|
 ========
However, the stories of the tower and antenna height can be changed with two constants:
STORIES = ?
ANTENNA = ?
For example, when they are both 0, the tower will look like:
    /\
   /~~\
  /~~~~\
 /~~~~~~\
 |[|--|]|
 |[|  |]|
 ========
When STORIES is 7 and ANTENNA is 3, the tower will be:
    /\
    <>
    <>
    <>
   /~~\
  /~~~~\
 /~~~~~~\
 |[][][]|
 |[][][]|
 |[][][]|
 |[][][]|
 |[][][]|
 |[][][]|
 |[][][]|
 |[|--|]|
 |[|  |]|
 ========


If you complete all of the problems with time remaining, work on the assignment!

You must attempt at least 3 of the 5 problems, and submit them to the lab-1 D2L dropbox, which closes at midnight.


Solutions: