Short Project 1

Vehicle – Printing the Model-T

In the this program, you will print out ASCII-art of one of the most famous vehicles of all time - the Model-T automobile! Name your program modelt.py.

Your program should be able to print different cars based on the width of the car. The number that your program accepts should control the width of the center part of the vehicle. A larger width value should make for a longer car, and vice-versa. The height of the vehicle will remain the same regardless of the width entered. Below are several examples of this program running with different values provided. Your program should match the look of the outputs exactly.

width = 0
car = build_car(width)
print(car, end="")
.-----------.
| ### ||  ###\
| ### ||  ####\.
D     ||  <>    |------+
|  ______      /______ |
 \/ /..\ \_____/ /..\ \|
    \__/         \__/
width = 5
car = build_car(width)
print(car, end="")
.----------------.
| ### ||  ########\
| ### ||  #########\.
D     ||       <>    |------+
|  ______           /______ |
 \/ /..\ \__________/ /..\ \|
    \__/              \__/
width = 12
car = build_car(width)
print(car, end="")
.-----------------------.
| ### ||  ###############\
| ### ||  ################\.
D     ||              <>    |------+
|  ______                  /______ |
 \/ /..\ \_________________/ /..\ \|
    \__/                     \__/

Any integer number 0 or greater should be supported. You don’t need to worry about handling negative numbers, fractions, or numbers with decimals.

Before You Begin

This section gives you a quick recap of what we covered in class or introduces any new tips or examples that might help you complete the assignment. Take a few minutes to read through it before you begin.

What are strings?

Any sequence of characters enveloped in quotes (single, double, triple). Your opening quotes need to match your closing quotes.

String literals:

"this is a string"
'this is also a string'

Use variable names:

my_name = "Julia Smith"

Concatenate strings

Use the + operator to “glue” strings together:

message = "Hi there"
punctuation = "!"
print(message + punctuation)
Hi there!

You can also use += to change to retrieve the string assigned to a variable, “glue” another string to it, and assign it back to the same variable name:

full_message = "" # start with an empty string
full_message += "Hi there"
full_message += "!"
print(full_message)
Hi there!

Writing your own function

Use the keyword def to define a function use () after your function name to list all the parameters.

def repeat_message(message, n):
  full_message = message * n
  return full_message

message = repeat_message("Hi there", 5)
print(message)
Hi thereHi thereHi thereHi thereHi there
  • What if I wanted to have a space between each string?
  • What if I wanted to have a line break between each string?