Preparing for the Blue Bridge Cup Python Group B Day1: Luogu Beginner 1 Problem Solving Record and Basic Syntax Quick Reference Notes

The first academic year after entering the undergraduate program is not easy, and in the blink of an eye, it's almost time to find a job. To easily tackle the Blue Bridge Cup, I chose Python, which I have some foundation in, focusing on cost-effectiveness. I no longer want to spend a lot of time dealing with C++ environment setup and complex syntax.

My overall preparation plan is clear: first, complete Luogu's problem sets 1-6 (sequence, branch, loop, array, string, function) to build a solid foundation, then move on to practicing the 500 real past questions on the Blue Bridge Cloud platform for the final sprint.

Today, I spent 3 hours successfully clearing Luogu's [Beginner 1: Sequential Structure]. Although the problems are basic, when actually coding, I still encountered many Python-specific 'pitfalls' and data processing details. For future review, I've compiled today's troubleshooting log and summarized syntax templates into this note.

1. Common Pitfalls for Beginners Writing Code

  1. Writing mathematical formulas directly as code

When solving P5708 [Triangle Area], the given Heron's formula is √[p(p-a)(p-b)(p-c)]. Following mathematical intuition, I casually wrote "p(p - a)".

Python immediately reported an error:
"TypeError: 'float' object is not callable".

It turns out Python doesn't recognize the omitted multiplication sign in algebra; it thinks "p" is a function and tries to call it. You must explicitly add the multiplication sign, writing "p * (p - a)".

  1. Forgetting that inputs are all 'strings'

While solving P1425 [Little Fish Swimming Time], calculating the time difference. I thought, just multiply hours by 60 to get minutes? So I wrote "a, b, c, d = input().split()", then directly used "c * 60" in the calculation.

The terminal instantly output a bunch of gibberish:
"1919191919..."
Then I remembered, the results from "split()" are all strings by default! In Python, multiplying a string by a number repeats it N times. Before calculation, you must first convert them to integers using "map(int, ...)".

  1. Knowledge Gaps: Formulas and Unit Conversions

Got stuck on B2029 [Elephant Drinking Water].
First, I completely blanked on the cylinder volume formula πr²h.

Second, the problem stated the elephant drinks 20 liters of water, but the bucket dimensions were in centimeters. I totally forgot the conversion 1 liter = 1000 cubic centimeters and pondered for a long time.

  1. Python Only Has Strings

Encountered a problem asking to output an uppercase letter. My first instinct was to look up ASCII codes, thinking of using a convoluted method like print(chr(ord(input())+32)).

Actually, Python doesn't have a separate char type; all single characters are strings of length 1. So for case conversion, directly using string methods .upper() or .lower() is the correct solution, e.g., input().strip().upper(), which is concise and direct. For such problems in the future, don't keep thinking about converting Unicode.

2. Core Syntax & Quick Reference Notes

Based on this problem-solving session, I reorganized the following core syntax points, which can be called a 'quick reference dictionary'.

  1. Input & Type Conversion
  1. Formatting Output Power Tool: f-string
    For problems requiring controlled formatting, strongly recommend f"{variable:format}". It avoids cumbersome string concatenation and rounding issues.
    (Remember this was also emphasized for the Computer Rank Exam; after the colon you can add fill, alignment, width, precision, type, etc., combine as needed.)
  1. Core Operations for Math & Time Calculations
    The Blue Bridge Cup often tests time and allocation problems; these operators must be mastered:
  1. String Processing Techniques

Today marks a good start for my preparation. Although it's just sequential structure, solidifying the basics and getting familiar with Python's 'temperament' is essential. Next up is challenging 'branch structure'. Keep going!