Menu
CoddyTech

Printing Without Format Codes

Lesson 2 of 48 in Coddy's Python for C Developers course.

C printf interprets a format string and requires argument types that match its conversions. Python print accepts objects, converts them to text, separates multiple arguments with spaces, and ends with a newline by default. Python single and double quotes both produce strings; there is no distinct character type. A hash outside a string begins a comment. A hash inside a quoted string stays data. The task keeps arbitrary input text intact, so do not trim it or treat its punctuation as syntax.

C: complete example.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
int main(void) {
    printf("%s %d\n", "Count:", 3);
    return 0;
}

Python: complete example.py

print("Count:", 3)

Watch the difference

C // begins a comment, but Python // performs floor division. Python does not understand printf conversion codes inside an ordinary print string.

Your code goes in main.py. The locked driver.py is the entry file, supplies execution and checks, and cannot be edited.

challenge icon

Challenge

Beginner

Accept one text line, including an empty line, quotes, or a hash. Output Message: followed by the unchanged text, then output It's Python on the next line. Disable the starter's diagnostic print. The supplied input() removes the terminating newline.

Keep the supplied input scaffold. Output only the requested results, with a newline after each line and no prompts.

C printf needs an explicit newline; Python print adds one by default. Python comments start with #.

Your code goes in main.py. The locked driver.py is the entry file, supplies execution and checks, and cannot be edited.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for C Developers

Practice on your own: Online Python compiler