This collection presents beginner-level programming exercises centered on sequential control flow—no branching or loops beyond basic iteration. Each problem emphasizes precise output formatting, arithmetic operations, string manipulation, and unit conversions.
Hello, World!
Output the exact string Hello,World!, with no leading/trailing spaces, proper capitalization, and no space after the comma.
print("Hello,World!")
Diamond Pattern with Asterisks
Print a diagonally oriented diamond composed of asterisks (*) where the longest row contains five characters. The pattern must be symmetric and centered.
for row in range(-2, 3):
spaces = abs(row)
stars = 5 - 2 * spaces
print(" " * spaces + "*" * stars)
ASCII Art Scene Rendering
Output a fixed multi-line ASCII art representation of a game scene using only printable characters and newlines.
scene = """ ********
************
####....#.
#..###.....##....
###.......###### ### ###
........... #...# #...#
##*####### #.#.# #.#.#
####*******###### #.#.# #.#.#
...#***.****.*###.... #...# #...#
....**********##..... ### ###
....**** *****....
#### ####
###### ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
########################################## #----------#
#.....#......##.....#......##.....#......# #----------#
########################################## #----------#
#.#..#....#..##.#..#....#..##.#..#....#..# #----------#
########################################## ############"""
print(scene)
Integer Addition Calculator
Read two integers separated by whitespace and print their sum. Input values may be negative; absolute values do not exceed 10⁹.
a, b = map(int, input().split())
print(a + b)
Isosceles Triangle with Custom Character
Given a single ASCII character, print a 3-line isosceles triangle with base width 5: first line has 1 character, second has 3, third has 5—each centered with leading spaces.
ch = input().strip()
for i in range(1, 6, 2):
padding = (5 - i) // 2
print(" " * padding + ch * i)
Apple Distribution Calculation
Compute total apples needed when each of n students receives k apples. Both inputs are positive integers ≤ 10⁹.
k, n = map(int, input().split())
print(k * n)
Uppercase Conversion
Read a lowercase ASCII letter and output its uppercase equivalent.
char = input().strip()
print(char.upper())
Floating-Point Digit Reversal
Given a decimal number between 100.0 and 999.9 (inclusive), reverse all digits—including those before and after the decimal point—while preserving the decimal separator’s position in the output.
s = input().strip()
reversed_str = s[::-1]
print(reversed_str)
Beverage Allocation and Container Counting
Given t milliliters of drink and n students, compute: (1) milliliters per student (rounded to exactly three decimal places), and (2) total cups required (2 per student, integer).
t, n = map(float, input().split())
per_student = t / n
total_cups = int(n) * 2
print(f"{per_student:.3f}")
print(total_cups)
Triangle Area via Heron’s Formula
Given side lengths a, b, c of a valid triangle, compute its area using Heron’s formula and round to one decimal place.
a, b, c = map(float, input().split())
s = (a + b + c) / 2
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
print(f"{area:.1f}")
Latest Departure Time Calculation
Given distance s (meters) and walking speed v (m/min), determine latest 24-hour departure time (HH:MM format) to arrive at school by 08:00, including a mandatory 10-minute waste-sorting stop.
s, v = map(int, input().split())
travel_min = (s + v - 1) // v # ceiling division
total_delay = travel_min + 10
arrival_minutes = 8 * 60
departure_minutes = (arrival_minutes - total_delay) % (24 * 60)
hh, mm = divmod(departure_minutes, 60)
print(f"{hh:02d}:{mm:02d}")
Water Bucket Count for Elephant
An elephant needs 20 liters (20,000 mL) of water. Given bucket depth h and radius r (in cm), compute minimum full buckets required using π ≈ 3.14.
import math
h, r = map(int, input().split())
volume_ml = 3.14 * r * r * h
buckets = math.ceil(20000 / volume_ml)
print(buckets)
Swimming Duration in Hours and Minutes
Given start time (a:b) and end time (c:d) on the same day (24-hour format), output duration as hours minutes, where minutes < 60.
a, b, c, d = map(int, input().split())
start_total = a * 60 + b
end_total = c * 60 + d
duration = end_total - start_total
print(duration // 60, duration % 60)
Maximum Pens Purchasable
Each pen costs 19 jiao (1.9 yuan). Given a yuan and b jiao (0 ≤ b ≤ 9), compute maximum pens purchasable using integer division.
a, b = map(int, input().split())
total_jiao = a * 10 + b
print(total_jiao // 19)
Weighted Course Score Calculation
Compute final score from homework (20%), quiz (30%), and final exam (50%), all scored out of 100. Round result to nearest integer.
hw, quiz, final = map(int, input().split())
score = 0.2 * hw + 0.3 * quiz + 0.5 * final
print(round(score))