Python Mini Project — a Small CLI
You are labeling one box. You want a program that asks what is in the box, asks how many, and then writes one line. You will type mug, then 4. The last line on the screen will be mug 4.
def label(item, count):
return f"{item} {count}"
item = input("item: ")
count = input("how many: ")
print(label(item, count))
The screen shows three lines. The program waits at item: and you type mug, then press Enter. item holds mug. The question item: is only shown while the program waits, so it is not stored. The program then waits at how many: and you type 4, then press Enter. count holds 4, the characters you typed. The question how many: is not stored either. print writes the line label returns. That line is mug 4. The space between mug and 4 is in the return line, between the two answers. The program is done. There is no fourth line.
The last line is the label, not the questions. It is not item: mug, and it is not how many: 4. Those questions stay on the first two lines, beside what you typed. label receives only mug and 4. If the return line said f"{item}: {count}", the last line would be mug: 4, but that is not the line in this program. This return line puts one space between the answers, so the last line is mug 4.
You can now put two questions and one label in a single program. Type mug, then 4, and the last line is mug 4. The next page runs this program only when you start this file yourself.
Two questions, then one label
You type mug, then 4. The last line is mug 4. The questions stay on the waiting lines. The next page runs this program only when you start this file yourself.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top