= 0
width = build_car(width)
car print(car, end="")
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.
.-----------. | ### || ###\ | ### || ####\. D || <> |------+ | ______ /______ | \/ /..\ \_____/ /..\ \| \__/ \__/
= 5
width = build_car(width)
car print(car, end="")
.----------------. | ### || ########\ | ### || #########\. D || <> |------+ | ______ /______ | \/ /..\ \__________/ /..\ \| \__/ \__/
= 12
width = build_car(width)
car 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.
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:
= "Julia Smith" my_name
print()
function
Print string literals:
print("Hi there")
Hi there
Print variables:
= "Hi there"
message print(message)
Hi there
Concatenate strings
Use the +
operator to “glue” strings together:
= "Hi there"
message = "!"
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:
= "" # start with an empty string
full_message += "Hi there"
full_message += "!"
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):
= message * n
full_message return full_message
= repeat_message("Hi there", 5)
message 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?