0% found this document useful (0 votes)
2 views11 pages

Pps Code Comprehension

Uploaded by

Kartik Munipalli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Pps Code Comprehension

Uploaded by

Kartik Munipalli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Premium display item checker

Palindrome based Product classification

K rtikey munip lli Arn v T Ajith Umesh Chowdh ry Rhiddhi Kum ri


a
a
a
a
a
a
Project overview

Objective: Automatically identify products for premium display based on palindromic Product IDs.

C Programming
Mathematical Approach.

🐍 Python
String Manipulation.
What is palindrome?

•Definition: A number that reads the same forwards and


backwards!
•1221 ↔
•1221✓
•121✓
•Palindrome
•5 ✓
•Palindrome
•123✗
•Not Palindrome
C program how it works?

•1 Get the number from user


•2 Reverse the number mathematically


•3 Compare original with reversed


•if (original == reversed) → PREMIUM!
C program example : 1221

•1 1221 % 10 = 1 (last digit)


reversed = 0 × 10 + 1 = 1
1221 / 10 = 122
•2 122 % 10 = 2
reversed = 1 × 10 + 2 = 12
122 / 10 = 12
•3 12 % 10 = 2
reversed = 12 × 10 + 2 = 122
12 / 10 = 1
•4 1 % 10 = 1
reversed = 122 × 10 + 1 = 1221
1 / 10 = 0 (Stop!)
1221 == 1221 → PALINDROME! ✓
Python - How it works?
•1 Get and convert to string


•2 Reverse using [::-1]


•[::-1] means "reverse the string"
•3 Compare strings


•if id_string == reversed_string → PREMIUM!
"1221” [::-1] "1221"
What happens with Single digit numbers?

• ALL SINGLE DIGIT NUMBERS ARE ALWAYS PALINDROMES


• Forward: 5
5 7
Forward: 7
9
Forward: 9
Backward: 5 Backward: 7 Backward: 9
✓ ✓ ✓

Why? Only ONE digit → Same forwards and backwards!


C program VS Python program

C Language

• Math operations (%, /)


🔵 C Language
• Digit by digit reversal 🐍 Python
• steps
• More •
• Math
• Very fast operations (%, /) • String slicing [::-1]
• Digit by digit reversal • One line reversal
• More steps • Simpler code
• Very fast • Easier for beginners

✅ Both Give Same Results!


Test examples

• Product ID: 1221


Forward: 1-2-2-1 | Backward: 1-2-2-1
✓ PREMIUM
• Product ID: 5
Forward: 5 | Backward: 5
✓ PREMIUM (Single Digit)
• Product ID: 1234
Forward: 1-2-3-4 | Backward: 4-3-2-1
✗ STANDARD
• Product ID: 121
Forward: 1-2-1 | Backward: 1-2-1
✓ PREMIUM
Conclusion

✅ Key Takeaways
• Palindromes read same forwards & backwards
• Single digits (0-9) are ALWAYS palindromes
• C uses math, Python uses strings
• Both methods work perfectly!

🏪 Real-World 📚 Skills
Warehouse management Loop logic
Automated sorting Problem solving
THANK YOU

You might also like