So far you’ve covered:
- How to run Python in the REPL and via scripts
- Numbers (integers and floats) and the key operators
- Assigning values to variables and choosing names
- Working with strings plus
print/input
Combining these pieces already lets you build meaningful mini-programs. The more you experiment, the deeper your understanding becomes.
Challenge 1: Temperature converter #
Create a program that converts Fahrenheit to Celsius using C = (F - 32) * 5 / 9.
Enter Fahrenheit: 77
25.0 °C
inputreturns a string, so convert it before calculating. Useround()if you want to limit decimal places.
This version prints one decimal place.
fahrenheit_text = input("Enter Fahrenheit: ")
fahrenheit = float(fahrenheit_text)
celsius = (fahrenheit - 32) * 5 / 9
print(f"{round(celsius, 1)} °C")Challenge 2: Alarm clock #
Ask for the current time (hour and minute, 24-hour format) and how many minutes until the alarm should ring, then display the alarm time.
Current hour (0-23): 21
Current minute (0-59): 30
Alarm in how many minutes? 90
Alarm time: 23:00
To stay within 24 hours, take the total minutes and use the remainder of dividing by
24 * 60.
This solution keeps everything within one day using modulo arithmetic.
hour = int(input("Current hour (0-23): "))
minute = int(input("Current minute (0-59): "))
after = int(input("Alarm in how many minutes? "))
total = hour * 60 + minute + after
total %= 24 * 60 # wrap around at 24 hours
alarm_hour = total // 60
alarm_minute = total % 60
print(f"Alarm time: {alarm_hour:02d}:{alarm_minute:02d}")
Challenge 3: Simple budget tracker (extended) #
Gather expenses for each day of a week, then display the total and the average. Start with plain variables, then refactor with lists or loops if you can.
Monday expense: 1200
Tuesday expense: 980
...
Total: xxxx yen
Average: xxxx yen
Whenever you see repeated patterns, consider how the loops you’ll learn next could simplify the code.
This is the minimal version using only variables.
mon = int(input("Monday expense: "))
tue = int(input("Tuesday expense: "))
wed = int(input("Wednesday expense: "))
thu = int(input("Thursday expense: "))
fri = int(input("Friday expense: "))
sat = int(input("Saturday expense: "))
sun = int(input("Sunday expense: "))
total = mon + tue + wed + thu + fri + sat + sun
average = total / 7
print(f"Total: {total} yen")
print(f"Average: {average:.1f} yen")
Using a list makes it easier to move to loops later.
Common stumbling blocks #
| Issue | Cause & remedy |
|---|---|
NameError: name 'value' is not defined | The variable is used before assignment or has a typo. Check your ordering and spelling. |
ValueError: invalid literal for int() | The string you convert with int() contains non-numeric characters. Validate the input or handle the exception (covered later). |
TypeError when concatenating strings | You tried to combine numbers and strings with +. Use f-strings or str() to convert numbers first. |
You’ve completed “01 Python Basic Syntax”. Next up: conditionals and loops for more dynamic programs. Take a break, then revisit any sections you’d like to reinforce by coding again.