Determine Century
Take a year and print the corresponding century (e.g., "19th century").
AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 9 of 10
determine-century.py
1# Take year2year = int(input("Enter a year: "))34# Calculate century5if year % 100 == 0:6 century = year // 1007else:8 century = (year // 100) + 1910# Format century11if century == 1:12 suffix = "st"13elif century == 2:14 suffix = "nd"15elif century == 3:16 suffix = "rd"17else:18 suffix = "th"1920print(f"{century}{suffix} century")
Output
Enter a year: 2024 21st century Enter a year: 1900 19th century Enter a year: 1950 20th century
What's going on
Calculate century from year.
Key Concepts:
If year divisible by 100: century = year/100
Otherwise: century = (year/100) + 1
Add appropriate suffix (st, nd, rd, th)
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum