Part of the series

Several example codes

~1 min read • Updated Oct 11, 2025

Program Overview

This Python program reads an integer from the user, representing the number of trips.
Using a for loop, it prints the character '7' that many times in the terminal.
This exercise helps reinforce basic loop structures and character repetition in Python.


Python Code:


def print_sevens(n):
    for i in range(n):
        print("7", end=" ")
    print()

# Run the program
trips = int(input("Enter number of trips: "))
print_sevens(trips)

Sample Output (input: 5):


7 7 7 7 7

Step-by-Step Explanation:

- The program first reads the number of trips from the user
- A for loop runs for that many iterations
- In each iteration, it prints the character '7' followed by a space
- The result is a single line of repeated '7' characters


Written & researched by Dr. Shahin Siami