<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SAINAPEI LENAPUNYA </title>
    <description>The latest articles on DEV Community by SAINAPEI LENAPUNYA  (@sanaipei001).</description>
    <link>https://dev.to/sanaipei001</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1482654%2F5784c3e2-0ce6-45ac-bddd-5340f3062a9f.jpg</url>
      <title>DEV Community: SAINAPEI LENAPUNYA </title>
      <link>https://dev.to/sanaipei001</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanaipei001"/>
    <language>en</language>
    <item>
      <title>Day 9: Temperature Converter - From Celsius to Fahrenheit - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Sat, 22 Nov 2025 13:29:18 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-9-temperature-converter-from-celsius-to-fahrenheit-30-days-of-python-challenge-4672</link>
      <guid>https://dev.to/sanaipei001/day-9-temperature-converter-from-celsius-to-fahrenheit-30-days-of-python-challenge-4672</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 9!
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 9 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and we're building another essential converter a &lt;strong&gt;temperature converter&lt;/strong&gt;! &lt;/p&gt;

&lt;p&gt;Today, we're creating a converter that switches between Celsius and Fahrenheit. Let's keep building!&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 9: Temperature Converter - Working with Formulas
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;Build a Temperature Converter&lt;/strong&gt;. Following yesterday's weight converter pattern, I'm creating another practical tool using conversion formulas!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;Building this temperature converter taught me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to implement &lt;strong&gt;mathematical formulas&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;How to use the &lt;strong&gt;&lt;code&gt;.upper()&lt;/code&gt;&lt;/strong&gt; method for case-insensitive input&lt;/li&gt;
&lt;li&gt;How to work with temperature scales and their conversion formulas&lt;/li&gt;
&lt;li&gt;How patterns from previous projects make new ones easier to build&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more I build, the more confident I become! 🔥&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 9:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 9 - Temperature conversion
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;c_to_f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;f_to_c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;

&lt;span class="n"&gt;choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Convert (C)elsius or (F)ahrenheit? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;choice&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;C&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Celsius: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; °C = &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;c_to_f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; °F&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Fahrenheit: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; °F = &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;f_to_c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; °C&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me explain each part:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;def c_to_f(c): return (c * 9/5) + 32&lt;/code&gt;&lt;/strong&gt; - This one-line function converts Celsius to Fahrenheit using the standard formula: °F = (°C × 9/5) + 32. Notice how we can write complex formulas right in the return statement!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;def f_to_c(f): return (f - 32) * 5/9&lt;/code&gt;&lt;/strong&gt; - The reverse conversion: °C = (°F - 32) × 5/9. These formulas are mathematical standards for temperature conversion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;choice = input("Convert (C)elsius or (F)ahrenheit? ").upper()&lt;/code&gt;&lt;/strong&gt; - Here's something new! The &lt;strong&gt;&lt;code&gt;.upper()&lt;/code&gt;&lt;/strong&gt; method converts whatever the user types to UPPERCASE. So whether they type "c", "C", or even "c", it becomes "C". This makes our program more user-friendly!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;if choice == "C":&lt;/code&gt;&lt;/strong&gt; - If the user chose Celsius (meaning they want to convert FROM Celsius to Fahrenheit).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;c = float(input("Celsius: "))&lt;/code&gt;&lt;/strong&gt; - Get the temperature in Celsius.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print(f"{c} °C = {c_to_f(c):.2f} °F")&lt;/code&gt;&lt;/strong&gt; - Display the result with the degree symbols (°C and °F) and format to 2 decimal places. The &lt;code&gt;:.2f&lt;/code&gt; ensures we don't get messy decimals!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;else:&lt;/code&gt;&lt;/strong&gt; - If the user chose anything other than "C" (presumably "F"), we convert from Fahrenheit to Celsius.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The else block&lt;/strong&gt; - Same pattern but reversed!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Convert (C)elsius or (F)ahrenheit? C
Celsius: 25
25.0 °C = 77.00 °F
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you convert the other way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Convert (C)elsius or (F)ahrenheit? F
Fahrenheit: 98.6
98.6 °F = 37.00 °C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdmg12gsuxng61w6y7d6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjdmg12gsuxng61w6y7d6.png" alt=" " width="800" height="38"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Temperature Conversion Formulas 🎯
&lt;/h2&gt;

&lt;p&gt;Here are the formulas we're using:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Celsius to Fahrenheit:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Formula: °F = (°C × 9/5) + 32&lt;/li&gt;
&lt;li&gt;Example: 0°C = 32°F (freezing point of water)&lt;/li&gt;
&lt;li&gt;Example: 100°C = 212°F (boiling point of water)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Fahrenheit to Celsius:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Formula: °C = (°F - 32) × 5/9&lt;/li&gt;
&lt;li&gt;Example: 32°F = 0°C&lt;/li&gt;
&lt;li&gt;Example: 98.6°F = 37°C (normal body temperature)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why This Is Useful🔗
&lt;/h2&gt;

&lt;p&gt;Temperature converters are incredibly practical:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Travel&lt;/strong&gt;: Understanding weather forecasts in different countries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cooking&lt;/strong&gt;: Converting recipe temperatures for your oven&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Science&lt;/strong&gt;: Working with international temperature standards&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Health&lt;/strong&gt;: Understanding body temperature readings&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weather&lt;/strong&gt;: Following international news and climate data&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways💡
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Mathematical formulas can be directly written in Python functions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.upper()&lt;/code&gt; converts strings to uppercase for case-insensitive comparisons&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.lower()&lt;/code&gt; also exists for converting to lowercase&lt;/li&gt;
&lt;li&gt;Temperature conversions use specific mathematical formulas&lt;/li&gt;
&lt;li&gt;The same project pattern (menu → input → calculate → display) works for many converters&lt;/li&gt;
&lt;li&gt;Building similar projects reinforces your skills&lt;/li&gt;
&lt;li&gt;Formatting with &lt;code&gt;:.2f&lt;/code&gt; keeps output clean and professional&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 10&lt;/strong&gt;, I'll be exploring &lt;strong&gt;logical operators&lt;/strong&gt;! We'll learn how to combine multiple conditions using AND, OR, and NOT. Time to make our decision-making even more powerful! 🧠&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Connect!💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do you prefer Celsius or Fahrenheit?&lt;/li&gt;
&lt;li&gt;Have you ever been confused by temperature in a different country?&lt;/li&gt;
&lt;li&gt;What other temperature scales should we add (Kelvin, maybe)?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, try adding Kelvin conversion to your program and share your enhanced version! &lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 10 takes us deeper into logic! &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Happy Coding! *&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>temperatureconverter</category>
    </item>
    <item>
      <title>Day 8: Weight Converter - Building Practical Tools - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Sat, 22 Nov 2025 13:19:22 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-8-weight-converter-building-practical-tools-30-days-of-python-challenge-5gk</link>
      <guid>https://dev.to/sanaipei001/day-8-weight-converter-building-practical-tools-30-days-of-python-challenge-5gk</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 8!
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 8 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and we're building another practical tool a &lt;strong&gt;weight converter&lt;/strong&gt;! &lt;/p&gt;

&lt;p&gt;If you missed the previous days:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Day 1: Print Statements]&lt;/li&gt;
&lt;li&gt;[Day 2: Variables and Data Types]&lt;/li&gt;
&lt;li&gt;[Day 3: Type Casting]&lt;/li&gt;
&lt;li&gt;[Day 4: User Input]&lt;/li&gt;
&lt;li&gt;[Day 5: Arithmetic Operators]&lt;/li&gt;
&lt;li&gt;[Day 6: If Statements]&lt;/li&gt;
&lt;li&gt;[Day 7: Simple Calculator]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're creating a converter that switches between kilograms and pounds. Let's build something useful!&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 8: Weight Converter - Functions with Parameters
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;Build a Weight Converter&lt;/strong&gt;. After yesterday's calculator, I'm taking functions to the next level by creating specialized converters with &lt;strong&gt;parameters&lt;/strong&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;Building this weight converter taught me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to write &lt;strong&gt;one-line functions&lt;/strong&gt; for simple operations&lt;/li&gt;
&lt;li&gt;How to use &lt;strong&gt;function parameters&lt;/strong&gt; to pass values into functions&lt;/li&gt;
&lt;li&gt;How to format numbers with specific decimal places using &lt;strong&gt;f-strings&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;How to create a menu-driven program with user choices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is getting more practical every day! &lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 8:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 8 - Weight conversion (kg &amp;lt;-&amp;gt; lbs)
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;kg_to_lbs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kg&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;kg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;2.20462&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lbs_to_kg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lbs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;lbs&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;2.20462&lt;/span&gt;

&lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Convert (1) kg-&amp;gt;lbs or (2) lbs-&amp;gt;kg? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;kg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Kg: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;kg&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; kg = &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;kg_to_lbs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; lbs&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;lbs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Lbs: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;lbs&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; lbs = &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;lbs_to_kg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lbs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; kg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me explain each part:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;def kg_to_lbs(kg): return kg * 2.20462&lt;/code&gt;&lt;/strong&gt; - This is a &lt;strong&gt;one-line function&lt;/strong&gt;! Instead of using multiple lines, I put everything on one line. The function takes a parameter &lt;code&gt;kg&lt;/code&gt; and returns the value in pounds. The conversion factor is 2.20462 (1 kg = 2.20462 lbs).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;def lbs_to_kg(lbs): return lbs / 2.20462&lt;/code&gt;&lt;/strong&gt; - Similar function, but converts pounds to kilograms by dividing instead of multiplying.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;mode = input("Convert (1) kg-&amp;gt;lbs or (2) lbs-&amp;gt;kg? ")&lt;/code&gt;&lt;/strong&gt; - We give users a choice! This makes our program more flexible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;if mode == "1":&lt;/code&gt;&lt;/strong&gt; - If the user chooses option 1, we convert kg to lbs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;kg = float(input("Kg: "))&lt;/code&gt;&lt;/strong&gt; - Get the weight in kilograms from the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;print(f"{kg} kg = {kg_to_lbs(kg):.2f} lbs")&lt;/code&gt;&lt;/strong&gt; - This is where the magic happens! Let me break down this f-string:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{kg}&lt;/code&gt; - Shows the original weight&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{kg_to_lbs(kg):.2f}&lt;/code&gt; - Calls our function AND formats it to 2 decimal places. The &lt;code&gt;:.2f&lt;/code&gt; means "format as a float with 2 decimal places."&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;else:&lt;/code&gt;&lt;/strong&gt; - If the user chooses anything other than "1", we convert lbs to kg.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The else block&lt;/strong&gt; - Works the same way but in reverse!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Convert (1) kg-&amp;gt;lbs or (2) lbs-&amp;gt;kg? 1
Kg: 70
70.0 kg = 154.32 lbs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you convert the other way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Convert (1) kg-&amp;gt;lbs or (2) lbs-&amp;gt;kg? 2
Lbs: 150
150.0 lbs = 68.04 kg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1enf7fwn0g4s8fmcah6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1enf7fwn0g4s8fmcah6.png" alt=" " width="800" height="37"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  New Concepts Introduced 🎯
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;One-Line Functions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compact way to write simple functions&lt;/li&gt;
&lt;li&gt;Format: &lt;code&gt;def name(param): return value&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Great for simple calculations and conversions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Function Parameters:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Values you pass INTO a function&lt;/li&gt;
&lt;li&gt;The function uses these values to perform operations&lt;/li&gt;
&lt;li&gt;Example: &lt;code&gt;kg_to_lbs(70)&lt;/code&gt; passes 70 as the parameter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;String Formatting with Decimals:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:.2f&lt;/code&gt; formats numbers to 2 decimal places&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:.1f&lt;/code&gt; would be 1 decimal place, &lt;code&gt;:.3f&lt;/code&gt; would be 3, etc.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;f&lt;/code&gt; means "floating-point number"&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Applications🔗
&lt;/h2&gt;

&lt;p&gt;Weight converters are super practical:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Travel&lt;/strong&gt;: Understanding luggage weight limits in different countries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fitness&lt;/strong&gt;: Tracking weight in your preferred unit&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cooking&lt;/strong&gt;: Converting recipe measurements&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Science&lt;/strong&gt;: Working with international standards&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Takeaways💡
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functions can be written in one line for simple operations&lt;/li&gt;
&lt;li&gt;Parameters let you pass data into functions&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;:.2f&lt;/code&gt; formatting rounds numbers to 2 decimal places&lt;/li&gt;
&lt;li&gt;Menu-driven programs give users choices&lt;/li&gt;
&lt;li&gt;One conversion factor (2.20462) lets you convert both ways&lt;/li&gt;
&lt;li&gt;F-strings can call functions AND format their output in one go&lt;/li&gt;
&lt;li&gt;Building practical tools makes programming more rewarding!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 9&lt;/strong&gt;, I'll be building a &lt;strong&gt;temperature converter&lt;/strong&gt;! We'll convert between Celsius, Fahrenheit, and maybe even Kelvin. More unit conversions ahead! &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Connect! 💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have you ever needed to convert weights between units?&lt;/li&gt;
&lt;li&gt;What other converters would be useful to build?&lt;/li&gt;
&lt;li&gt;Did the one-line function format surprise you?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, try adding more units (like grams or ounces) to your converter and share your results! &lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 9 continues building practical tools! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Coding!&lt;/strong&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 7: Simple Calculator - Putting It All Together - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Sat, 22 Nov 2025 10:20:29 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-7-simple-calculator-putting-it-all-together-30-days-of-python-challenge-i9d</link>
      <guid>https://dev.to/sanaipei001/day-7-simple-calculator-putting-it-all-together-30-days-of-python-challenge-i9d</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 7!
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 7 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and today is EXTRA exciting because we're building our &lt;strong&gt;first real project&lt;/strong&gt; a calculator! &lt;/p&gt;

&lt;p&gt;If you missed the previous days:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Day 1: Print Statements]&lt;/li&gt;
&lt;li&gt;[Day 2: Variables and Data Types]&lt;/li&gt;
&lt;li&gt;[Day 3: Type Casting]&lt;/li&gt;
&lt;li&gt;[Day 4: User Input]&lt;/li&gt;
&lt;li&gt;[Day 5: Arithmetic Operators]&lt;/li&gt;
&lt;li&gt;[Day 6: If Statements]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're combining everything we've learned into a functional calculator. Let's build something awesome!&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 7: Simple Calculator - Our First Real Project
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;Build a Calculator&lt;/strong&gt;. This is where all our previous lessons come together! We're using user input, type casting, arithmetic operators, if statements, and introducing something new—&lt;strong&gt;functions&lt;/strong&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;Building this calculator taught me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to organize code into reusable &lt;strong&gt;functions&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;How to handle user input for calculations&lt;/li&gt;
&lt;li&gt;How to validate operations and prevent errors&lt;/li&gt;
&lt;li&gt;How all the concepts connect to create something functional&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This feels like a huge milestone! 🎯&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 7:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 7 - Calculator
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;First number: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Operator (+ - * /): &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Second number: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Cannot divide by zero&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid operator&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Result:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me explain this step by step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;def calculator():&lt;/code&gt;&lt;/strong&gt; - This creates a &lt;strong&gt;function&lt;/strong&gt; named &lt;code&gt;calculator&lt;/code&gt;. Functions are reusable blocks of code. The &lt;code&gt;def&lt;/code&gt; keyword means "define." Think of it as creating your own custom command!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a = float(input("First number: "))&lt;/code&gt;&lt;/strong&gt; - We get the first number from the user and convert it to a float (decimal). Remember type casting from Day 3? Here it is in action!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;op = input("Operator (+ - * /): ")&lt;/code&gt;&lt;/strong&gt; - We ask the user which operation they want to perform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;b = float(input("Second number: "))&lt;/code&gt;&lt;/strong&gt; - Getting the second number, also as a float.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;if op == "+":&lt;/code&gt;&lt;/strong&gt; - Checking which operator was entered. If it's addition, we return the sum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;return a + b&lt;/code&gt;&lt;/strong&gt; - The &lt;code&gt;return&lt;/code&gt; keyword sends the result back. This is how functions give us answers!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The other operations&lt;/strong&gt; - Similar checks for subtraction, multiplication, and division.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;return a / b if b != 0 else "Cannot divide by zero"&lt;/code&gt;&lt;/strong&gt; - This is a &lt;strong&gt;conditional expression&lt;/strong&gt;! It checks if &lt;code&gt;b&lt;/code&gt; is not zero before dividing. If it is zero, we return an error message. Smart, right?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;return "Invalid operator"&lt;/code&gt;&lt;/strong&gt; - If the user enters something other than +, -, *, or /, we return this message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print("Result:", calculator())&lt;/code&gt;&lt;/strong&gt; - This &lt;strong&gt;calls&lt;/strong&gt; (runs) our function and prints the result!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First number: 15
Operator (+ - * /): +
Second number: 7
Result: 22.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you try division:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First number: 20
Operator (+ - * /): /
Second number: 4
Result: 5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it even handles errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First number: 10
Operator (+ - * /): /
Second number: 0
Result: Cannot divide by zero
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7k3oy0sq2ihwxqwa2l76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7k3oy0sq2ihwxqwa2l76.png" alt=" " width="800" height="54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F789zfskit1w2xnj3xrkd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F789zfskit1w2xnj3xrkd.png" alt=" " width="800" height="55"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  New Concepts Introduced🎯
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Functions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defined with &lt;code&gt;def function_name():&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Can take inputs (parameters) and give outputs (return values)&lt;/li&gt;
&lt;li&gt;Make code reusable and organized&lt;/li&gt;
&lt;li&gt;Called by writing the function name followed by parentheses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Return Statement:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sends a value back from the function&lt;/li&gt;
&lt;li&gt;Ends the function execution&lt;/li&gt;
&lt;li&gt;The returned value can be used elsewhere (like in our print statement)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Error Handling:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We prevent division by zero with a conditional check&lt;/li&gt;
&lt;li&gt;We validate the operator to ensure it's one we support&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connecting the Dots 🔗
&lt;/h2&gt;

&lt;p&gt;Look at how everything we've learned comes together:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Day 1 (Print)&lt;/strong&gt;: Used to display the result&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 2 (Variables)&lt;/strong&gt;: Store numbers and operators&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 3 (Type Casting)&lt;/strong&gt;: Convert input to floats&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 4 (User Input)&lt;/strong&gt;: Get numbers and operator from user&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 5 (Arithmetic)&lt;/strong&gt;: Perform the actual calculations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 6 (If Statements)&lt;/strong&gt;: Choose which operation to perform&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the power of programming—building blocks that create something bigger! &lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways💡
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functions organize code into reusable blocks using &lt;code&gt;def&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return&lt;/code&gt; sends values back from functions&lt;/li&gt;
&lt;li&gt;You can combine multiple if statements to handle different cases&lt;/li&gt;
&lt;li&gt;Always validate user input (like checking for division by zero)&lt;/li&gt;
&lt;li&gt;Conditional expressions (&lt;code&gt;value if condition else other_value&lt;/code&gt;) provide compact if-else logic&lt;/li&gt;
&lt;li&gt;Real programs combine multiple concepts to solve problems&lt;/li&gt;
&lt;li&gt;Building projects reinforces everything you've learned!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 8&lt;/strong&gt;, I'll be building a &lt;strong&gt;weight converter&lt;/strong&gt;! We'll create another practical tool that converts between different units. More real-world programming ahead! ⚖️&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's Connect!💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How does it feel to build your first project?&lt;/li&gt;
&lt;li&gt;What other calculators or tools do you want to build?&lt;/li&gt;
&lt;li&gt;Did the function concept click for you?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, try adding more operators (maybe exponentiation or modulus) and share your enhanced calculator! &lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 8 continues the project streak! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Coding!&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>python</category>
      <category>challenge</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Day 6: If Statements - Teaching Python to Make Decisions - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Thu, 20 Nov 2025 14:50:10 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-6-if-statements-teaching-python-to-make-decisions-30-days-of-python-challenge-4hl1</link>
      <guid>https://dev.to/sanaipei001/day-6-if-statements-teaching-python-to-make-decisions-30-days-of-python-challenge-4hl1</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 6!
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 6 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and today we're making our programs &lt;strong&gt;smart&lt;/strong&gt;! 🧠&lt;/p&gt;

&lt;p&gt;If you missed the previous days:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Day 1: Print Statements]&lt;/li&gt;
&lt;li&gt;[Day 2: Variables and Data Types]&lt;/li&gt;
&lt;li&gt;[Day 3: Type Casting]&lt;/li&gt;
&lt;li&gt;[Day 4: User Input]&lt;/li&gt;
&lt;li&gt;[Day 5: Arithmetic Operators]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're learning how to make decisions in our code using if statements. Let's give Python the power to think!&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 6: If Statements - Decision Making in Code 🤔
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;If Statements&lt;/strong&gt;. Until now, our code has been running line by line, doing the same thing every time. But what if we want different outcomes based on different conditions? That's where if statements come in!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;If statements are like giving your program a brain. They let you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check conditions and respond accordingly&lt;/li&gt;
&lt;li&gt;Create different paths through your code&lt;/li&gt;
&lt;li&gt;Make programs that adapt to user input&lt;/li&gt;
&lt;li&gt;Build logic into your applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where programming gets really powerful!&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 6 - If statements
&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter a number: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Positive&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Zero&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Negative&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter your age: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are an adult.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a minor.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me walk you through each part:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1: Checking if a number is positive, zero, or negative&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;num = int(input("Enter a number: "))&lt;/code&gt;&lt;/strong&gt; - Remember Day 3 (type casting) and Day 4 (user input)? Here they come together! We get user input and immediately convert it to an integer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;if num &amp;gt; 0:&lt;/code&gt;&lt;/strong&gt; - This is our first condition. The &lt;code&gt;&amp;gt;&lt;/code&gt; means "greater than." If the number is positive, Python executes the indented code below.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;elif num == 0:&lt;/code&gt;&lt;/strong&gt; - "elif" means "else if." If the first condition is false, Python checks this one. Notice the double equals &lt;code&gt;==&lt;/code&gt;? That's for comparison (single &lt;code&gt;=&lt;/code&gt; is for assignment).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;else:&lt;/code&gt;&lt;/strong&gt; - If none of the above conditions are true, this runs. It's our catch-all.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example 2: Checking if someone is an adult&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;if age &amp;gt;= 18:&lt;/code&gt;&lt;/strong&gt; - The &lt;code&gt;&amp;gt;=&lt;/code&gt; means "greater than or equal to." If someone is 18 or older, they're an adult.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;else:&lt;/code&gt;&lt;/strong&gt; - If they're not 18 or older, they're a minor. Simple!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enter a number: 5
Positive
Enter your age: 23
You are an adult.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you enter different values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enter a number: -3
Negative
Enter your age: 16
You are a minor.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1urlamcflhb62353krd2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1urlamcflhb62353krd2.png" alt=" " width="800" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison Operators 🎯
&lt;/h2&gt;

&lt;p&gt;Today I used several comparison operators. Here's the complete list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/strong&gt; Greater than&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/strong&gt; Less than&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/strong&gt; Greater than or equal to&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/strong&gt; Less than or equal to&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;==&lt;/code&gt;&lt;/strong&gt; Equal to (for comparison)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/strong&gt; Not equal to&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Important Things to Remember 🔑
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Indentation Matters!&lt;/strong&gt;&lt;br&gt;
Notice how the code under &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt; is indented? Python uses indentation to know what code belongs to which condition. This isn't just for style—it's required!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;if, elif, else Structure:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;if&lt;/code&gt;&lt;/strong&gt; - First condition to check&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;elif&lt;/code&gt;&lt;/strong&gt; - Additional conditions (you can have multiple)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;else&lt;/code&gt;&lt;/strong&gt; - Runs if none of the above are true (optional)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Assignment vs Comparison:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;=&lt;/code&gt; assigns a value: &lt;code&gt;age = 18&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; compares values: &lt;code&gt;age == 18&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Takeaways 💡
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If statements let your program make decisions based on conditions&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;if&lt;/code&gt; for the first condition, &lt;code&gt;elif&lt;/code&gt; for additional conditions, &lt;code&gt;else&lt;/code&gt; for everything else&lt;/li&gt;
&lt;li&gt;Comparison operators (&lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;) let you compare values&lt;/li&gt;
&lt;li&gt;Indentation is crucial in Python—it defines what code belongs to each condition&lt;/li&gt;
&lt;li&gt;You can combine type casting with user input to work with numbers&lt;/li&gt;
&lt;li&gt;Not every if statement needs an &lt;code&gt;elif&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt;—use what you need!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 7&lt;/strong&gt;, I'll be building a &lt;strong&gt;simple calculator&lt;/strong&gt;! We'll combine everything we've learned so far—user input, type casting, arithmetic operators, and if statements—to create something functional and fun! &lt;/p&gt;




&lt;h2&gt;
  
  
  Let's Connect!💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What's the first decision you want your program to make?&lt;/li&gt;
&lt;li&gt;Did the indentation requirement surprise you?&lt;/li&gt;
&lt;li&gt;Any creative uses for if statements you can think of?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, share what conditions you're checking in your programs! 🎲&lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 7 is going to be super practical! 💪&lt;/p&gt;

&lt;p&gt;Happy Coding! &lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>ifstatements</category>
    </item>
    <item>
      <title>Day 5: Arithmetic Operators - Python as Your Calculator - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Thu, 20 Nov 2025 14:34:34 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-5-arithmetic-operators-python-as-your-calculator-30-days-of-python-challenge-5884</link>
      <guid>https://dev.to/sanaipei001/day-5-arithmetic-operators-python-as-your-calculator-30-days-of-python-challenge-5884</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 5! 👋
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 5 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and today we're turning Python into our personal calculator! &lt;/p&gt;

&lt;p&gt;If you missed the previous days:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Day 1: Print Statements]&lt;/li&gt;
&lt;li&gt;[Day 2: Variables and Data Types]&lt;/li&gt;
&lt;li&gt;[Day 3: Type Casting]&lt;/li&gt;
&lt;li&gt;[Day 4: User Input]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're learning how to perform mathematical operations in Python. Let's crunch some numbers!&lt;/p&gt;

&lt;h2&gt;
  
  
  🔢 Day 5: Arithmetic Operators - Doing the Math
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;Arithmetic Operators&lt;/strong&gt;. Python isn't just for text and data—it's incredibly powerful for calculations! Whether you're building a calculator app, analyzing data, or solving problems, understanding arithmetic is essential.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;Python has a full set of arithmetic operators that let you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Perform basic calculations (add, subtract, multiply, divide)&lt;/li&gt;
&lt;li&gt;Do advanced operations (exponentiation, modulus)&lt;/li&gt;
&lt;li&gt;Work with different types of division&lt;/li&gt;
&lt;li&gt;Build the foundation for data analysis and algorithms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of these operators surprised me—especially floor division and modulus!&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 5:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 5 - Arithmetic
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="c1"&gt;#Addition
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a + b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Subtraction
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a - b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Multiplication
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a * b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Division
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a / b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Floor Division
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a // b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Exponentiation
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a ** b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Modulus
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a % b =&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me explain each arithmetic operator:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a + b&lt;/code&gt; (Addition)&lt;/strong&gt; - Simple addition! 8 + 3 = 11. This one's straightforward.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a - b&lt;/code&gt; (Subtraction)&lt;/strong&gt; - Basic subtraction. 8 - 3 = 5.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a * b&lt;/code&gt; (Multiplication)&lt;/strong&gt; - Use the asterisk &lt;code&gt;*&lt;/code&gt; for multiplication. 8 × 3 = 24.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a / b&lt;/code&gt; (Division)&lt;/strong&gt; - Regular division that gives you a decimal result. 8 ÷ 3 = 2.666...&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a // b&lt;/code&gt; (Floor Division)&lt;/strong&gt; - This was new to me! Floor division gives you the whole number part only, rounding down. 8 ÷ 3 = 2 (ignoring the remainder). Super useful!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a ** b&lt;/code&gt; (Exponentiation)&lt;/strong&gt; - This raises a number to a power. 8³ (8 × 8 × 8) = 512. The double asterisk &lt;code&gt;**&lt;/code&gt; means "to the power of."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;a % b&lt;/code&gt; (Modulus)&lt;/strong&gt; - Returns the remainder after division. 8 ÷ 3 = 2 remainder 2. So &lt;code&gt;8 % 3 = 2&lt;/code&gt;. This is incredibly useful for checking if numbers are even/odd or for cycling through ranges!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output 💻
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a + b = 11
a - b = 5
a * b = 24
a / b = 2.6666666666666665
a // b = 2
a ** b = 512
a % b = 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwt0grf06yv1s0tlbsvar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwt0grf06yv1s0tlbsvar.png" alt=" " width="800" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 Operator Quick Reference
&lt;/h2&gt;

&lt;p&gt;Here's a handy reference for all the arithmetic operators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;+&lt;/code&gt;&lt;/strong&gt; Addition - Adds two numbers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-&lt;/code&gt;&lt;/strong&gt; Subtraction - Subtracts second number from first&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;*&lt;/code&gt;&lt;/strong&gt; Multiplication - Multiplies two numbers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/&lt;/code&gt;&lt;/strong&gt; Division - Divides and gives decimal result&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;//&lt;/code&gt;&lt;/strong&gt; Floor Division - Divides and gives whole number (rounds down)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;`&lt;/strong&gt;`** Exponentiation - Raises to a power&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;%&lt;/code&gt;&lt;/strong&gt; Modulus - Gives remainder after division&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🤔 Real-World Uses
&lt;/h2&gt;

&lt;p&gt;You might wonder when you'd use these operators. Here are practical examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Addition/Subtraction&lt;/strong&gt;: Calculating totals, budgets, scores&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiplication/Division&lt;/strong&gt;: Converting units, splitting bills, scaling recipes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Floor Division&lt;/strong&gt;: Distributing items evenly, pagination (items per page)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exponentiation&lt;/strong&gt;: Calculating compound interest, exponential growth&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Modulus&lt;/strong&gt;: Checking even/odd numbers, creating cycles, validating data&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💡 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python supports all basic arithmetic operations&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt; for basic math&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;//&lt;/code&gt; gives you whole number division (floor division)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;**&lt;/code&gt; raises numbers to powers (exponentiation)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; (modulus) gives you the remainder—super useful for many algorithms!&lt;/li&gt;
&lt;li&gt;Regular division &lt;code&gt;/&lt;/code&gt; always returns a float, even if the result is a whole number&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;math&lt;/code&gt; module (imported at the top) provides even more mathematical functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 6&lt;/strong&gt;, I'll be diving into &lt;strong&gt;if statements&lt;/strong&gt; - learning how to make decisions in our code! We'll use comparison operators and control the flow of our programs based on conditions. Time to make Python think! 🧠&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Connect!💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which operator surprised you the most?&lt;/li&gt;
&lt;li&gt;Have you used modulus before? What for?&lt;/li&gt;
&lt;li&gt;What calculations do you want to build in Python?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, try creating your own calculator with these operators and share your results!&lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 6 is all about making decisions! 💪&lt;/p&gt;

&lt;p&gt;*Happy Coding! *&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>arithmeticoperator</category>
    </item>
    <item>
      <title>Day 4: User Input - Making Programs Interactive - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Thu, 20 Nov 2025 14:26:15 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-4-user-input-making-programs-interactive-30-days-of-python-challenge-1ef8</link>
      <guid>https://dev.to/sanaipei001/day-4-user-input-making-programs-interactive-30-days-of-python-challenge-1ef8</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 4! 👋
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 4 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and today is super exciting because we're making our programs &lt;strong&gt;interactive&lt;/strong&gt;! &lt;/p&gt;

&lt;p&gt;If you missed the previous days:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Day 1: Print Statements]&lt;/li&gt;
&lt;li&gt;[Day 2: Variables and Data Types]&lt;/li&gt;
&lt;li&gt;[Day 3: Type Casting]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're learning how to ask users questions and get their responses. Let's make our programs come alive!&lt;/p&gt;

&lt;h2&gt;
  
  
  💬 Day 4: User Input - Having a Conversation with Your Code
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;User Input&lt;/strong&gt;. Until now, we've been writing all the data ourselves. But what if we want our program to ask questions and respond based on what the user says? That's what the &lt;code&gt;input()&lt;/code&gt; function is for!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;input()&lt;/code&gt; function is like having a conversation with your program. You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ask users questions&lt;/li&gt;
&lt;li&gt;Store their responses in variables&lt;/li&gt;
&lt;li&gt;Use those responses to create personalized experiences&lt;/li&gt;
&lt;li&gt;Make your code dynamic and interactive!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Plus, I discovered &lt;strong&gt;f-strings&lt;/strong&gt; - a super clean way to combine text and variables!&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 4 - User input
&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s your name? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How old are you? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, you are &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; years old.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s your height in meters? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;is_student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Are you a student? (yes/no) &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;yes&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your height is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; meters and it is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;is_student&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;false&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; that you are a student.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me walk you through each part:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;name = input("What's your name? ")&lt;/code&gt;&lt;/strong&gt; - The &lt;code&gt;input()&lt;/code&gt; function displays the question and waits for the user to type something. Whatever they type gets stored in the &lt;code&gt;name&lt;/code&gt; variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;age = input("How old are you? ")&lt;/code&gt;&lt;/strong&gt; - Same thing here! The program pauses, waits for input, and stores it in &lt;code&gt;age&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print(f"Hello {name}, you are {age} years old.")&lt;/code&gt;&lt;/strong&gt; - This is an &lt;strong&gt;f-string&lt;/strong&gt;! Notice the &lt;code&gt;f&lt;/code&gt; before the quotes? It lets me put variables directly inside the text using curly braces &lt;code&gt;{}&lt;/code&gt;. So much cleaner than using commas!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;input("What's your height in meters? ")&lt;/code&gt;&lt;/strong&gt; - Getting more user input!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;.lower() == 'yes'&lt;/code&gt;&lt;/strong&gt; - This is clever! The &lt;code&gt;.lower()&lt;/code&gt; converts the input to lowercase (so "YES", "Yes", or "yes" all work), then checks if it equals 'yes'. This creates a boolean (True/False) value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;{'true' if is_student else 'false'}&lt;/code&gt;&lt;/strong&gt; - This is a &lt;strong&gt;conditional expression&lt;/strong&gt; inside the f-string. It displays 'true' if &lt;code&gt;is_student&lt;/code&gt; is True, otherwise 'false'. Pretty neat!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code and interact with it, you'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What's your name? Sanaipei
How old are you? 23
Hello Sanaipei, you are 23 years old.
What's your height in meters? 5.213
Are you a student? (yes/no) no
Your height is 5.213 meters and it is false that you are a student.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4x4dqocz75pk3v0eepo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4x4dqocz75pk3v0eepo.png" alt=" " width="800" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 Cool Things I Discovered
&lt;/h2&gt;

&lt;p&gt;Today I learned several new concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;input()&lt;/code&gt;&lt;/strong&gt; - Pauses the program and waits for user input&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;F-strings&lt;/strong&gt; (&lt;code&gt;f"text {variable}"&lt;/code&gt;) - Modern way to format strings in Python&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.lower()&lt;/code&gt;&lt;/strong&gt; - Converts text to lowercase&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conditional expressions&lt;/strong&gt; - Quick if/else inside expressions&lt;/li&gt;
&lt;li&gt;All &lt;code&gt;input()&lt;/code&gt; returns strings (remember Day 3's type casting? Super useful here!)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🤔 Why F-Strings Are Awesome
&lt;/h2&gt;

&lt;p&gt;Compare these two approaches:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Old way:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, you are&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;years old.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;F-string way:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, you are &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; years old.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;F-strings are cleaner, more readable, and you have better control over spacing and formatting!&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;input()&lt;/code&gt; makes your programs interactive by accepting user responses&lt;/li&gt;
&lt;li&gt;All input comes in as strings (use type casting if you need numbers!)&lt;/li&gt;
&lt;li&gt;F-strings (formatted string literals) are the modern way to combine text and variables&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;.lower()&lt;/code&gt; to make input case-insensitive&lt;/li&gt;
&lt;li&gt;You can use conditional expressions inside f-strings for dynamic messages&lt;/li&gt;
&lt;li&gt;Always include a prompt message in &lt;code&gt;input()&lt;/code&gt; so users know what to enter&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🚀 What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 5&lt;/strong&gt;, I'll be exploring &lt;strong&gt;arithmetic operators&lt;/strong&gt; - learning how to do calculations in Python. We'll add, subtract, multiply, divide, and more! Time to make Python our calculator! 🧮&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Let's Connect!
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What's the first interactive program you want to build?&lt;/li&gt;
&lt;li&gt;Have you tried f-strings yet? What do you think?&lt;/li&gt;
&lt;li&gt;Any creative ideas for using user input?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, share what questions you're asking users in your programs! 🎤&lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 5 is going to be mathematical! 💪&lt;/p&gt;

&lt;p&gt;*Happy Coding! *&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>userinput</category>
    </item>
    <item>
      <title>Day 3: Type Casting - Transforming Data Types - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Thu, 20 Nov 2025 14:17:55 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-3-type-casting-transforming-data-types-30-days-of-python-challenge-26ip</link>
      <guid>https://dev.to/sanaipei001/day-3-type-casting-transforming-data-types-30-days-of-python-challenge-26ip</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back to Day 3!
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 3 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and today we're diving into something really cool: &lt;strong&gt;type casting&lt;/strong&gt;! &lt;/p&gt;

&lt;p&gt;If you missed the previous days:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[Day 1: Print Statements]&lt;/li&gt;
&lt;li&gt;[Day 2: Variables and Data Types]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're learning how to transform data from one type to another. Let's jump in!&lt;/p&gt;

&lt;h2&gt;
  
  
  🔄 Day 3: Type Casting - The Shape Shifter
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;Type Casting&lt;/strong&gt;. Remember how on Day 2 we learned about different data types (strings, integers, floats)? Well, sometimes we need to convert data from one type to another. That's where type casting comes in!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;Type casting is like being a data magician 🪄. You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convert text numbers into actual numbers you can do math with&lt;/li&gt;
&lt;li&gt;Turn numbers into text for displaying messages&lt;/li&gt;
&lt;li&gt;Switch between integers and floats for different calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python gives us special functions to transform our data: &lt;code&gt;int()&lt;/code&gt;, &lt;code&gt;float()&lt;/code&gt;, &lt;code&gt;str()&lt;/code&gt;, and more!&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 3 - Type casting
&lt;/span&gt;&lt;span class="n"&gt;num_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;123&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_str&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;num_int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_int&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;num_float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_float&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;back_to_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num_int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;back_to_str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;back_to_str&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me explain each transformation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;num_str = "123"&lt;/code&gt;&lt;/strong&gt; - I start with "123" as a &lt;strong&gt;string&lt;/strong&gt; (notice the quotes). Right now, Python sees this as text, not a number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print(num_str, type(num_str))&lt;/code&gt;&lt;/strong&gt; - The &lt;code&gt;type()&lt;/code&gt; function is super useful! It tells us what data type we're working with. This will show us it's a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;num_int = int(num_str)&lt;/code&gt;&lt;/strong&gt; - Here's the magic! The &lt;code&gt;int()&lt;/code&gt; function converts our string "123" into an integer 123. Now we can do math with it!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;num_float = float(num_str)&lt;/code&gt;&lt;/strong&gt; - The &lt;code&gt;float()&lt;/code&gt; function converts "123" into a decimal number 123.0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;back_to_str = str(num_int)&lt;/code&gt;&lt;/strong&gt; - And we can go back! The &lt;code&gt;str()&lt;/code&gt; function turns our integer back into a string.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;123 &amp;lt;class 'str'&amp;gt;
123 &amp;lt;class 'int'&amp;gt;
123.0 &amp;lt;class 'float'&amp;gt;
123 &amp;lt;class 'str'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1w8yxwbh9cw0iubmskqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1w8yxwbh9cw0iubmskqq.png" alt=" " width="800" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how the value looks similar, but the type changes? That's type casting in action! 🎭&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯Type Casting Functions
&lt;/h2&gt;

&lt;p&gt;Here are the main type casting functions I used today:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;int()&lt;/code&gt;&lt;/strong&gt; - Converts to an integer (whole number)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;float()&lt;/code&gt;&lt;/strong&gt; - Converts to a float (decimal number)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/strong&gt; - Converts to a string (text)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;type()&lt;/code&gt;&lt;/strong&gt; - Not a casting function, but shows you what type your data is!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🤔 Why Does This Matter?
&lt;/h2&gt;

&lt;p&gt;You might wonder: "Why do I need to convert data types?" Great question! Here are real scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User input&lt;/strong&gt;: When someone types "25" into your program, it comes in as text. You need to convert it to a number to do calculations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Displaying results&lt;/strong&gt;: If you calculate 10 + 5 = 15, you might need to convert 15 to "15" to display it nicely in a message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data processing&lt;/strong&gt;: Working with files or databases often requires converting between types.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💡 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Type casting converts data from one type to another&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;int()&lt;/code&gt; to convert to integers, &lt;code&gt;float()&lt;/code&gt; to decimals, &lt;code&gt;str()&lt;/code&gt; to text&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;type()&lt;/code&gt; function helps you check what data type you're working with&lt;/li&gt;
&lt;li&gt;Type casting is essential when working with user input (coming tomorrow!)&lt;/li&gt;
&lt;li&gt;Python won't let you do math with strings, so converting is necessary&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 4&lt;/strong&gt;, I'll be diving into &lt;strong&gt;user input&lt;/strong&gt; - learning how to make our programs interactive by accepting input from users. We'll use what we learned today about type casting because user input always comes in as strings!&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Let's Connect!
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have you ever needed to convert data types in your code?&lt;/li&gt;
&lt;li&gt;Did you find the &lt;code&gt;type()&lt;/code&gt; function helpful?&lt;/li&gt;
&lt;li&gt;Any questions about type casting?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, try type casting with your own variables and share what you discover! 🔬&lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates. Day 4 is going to be interactive! 💪&lt;/p&gt;

&lt;p&gt;*Happy Coding! *&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>typecasting</category>
    </item>
    <item>
      <title>Day 2: Storing Information with Variables - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Thu, 20 Nov 2025 14:09:08 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-2-storing-information-with-variables-30-days-of-python-challenge-1oep</link>
      <guid>https://dev.to/sanaipei001/day-2-storing-information-with-variables-30-days-of-python-challenge-1oep</guid>
      <description>&lt;h2&gt;
  
  
  Welcome Back!
&lt;/h2&gt;

&lt;p&gt;Hey everyone! It's Day 2 of my &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and I'm so excited you're back! Yesterday we learned about the &lt;code&gt;print()&lt;/code&gt; function, and today we're leveling up by learning how to &lt;strong&gt;store and reuse information&lt;/strong&gt; with variables.&lt;/p&gt;

&lt;p&gt;If you missed Day 1, check it out [here] to catch up on print statements!&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 2: Variables - Your Data Containers
&lt;/h2&gt;

&lt;p&gt;Today's mission: &lt;strong&gt;Understanding Variables&lt;/strong&gt;. Think of variables as labeled boxes where you can store different types of information. Instead of typing the same information over and over, we store it once and use it everywhere!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;Variables are like name tags for your data. They let you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store information to use later&lt;/li&gt;
&lt;li&gt;Make your code more flexible and reusable&lt;/li&gt;
&lt;li&gt;Give meaningful names to your data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Python, creating a variable is super simple: just pick a name, use the equals sign (&lt;code&gt;=&lt;/code&gt;), and assign a value!&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Day 2 - Variables
&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sanaipei&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;My name is&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I am&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;years old&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;height_m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;5.213&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;My height is&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height_m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;meters&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;is_student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Am I a student?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;is_student&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me walk you through each part:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;name = "Sanaipei"&lt;/code&gt;&lt;/strong&gt; - This creates a variable called &lt;code&gt;name&lt;/code&gt; and stores the text "Sanaipei" in it. This is a &lt;strong&gt;string&lt;/strong&gt; (text data).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print("My name is", name)&lt;/code&gt;&lt;/strong&gt; - Notice how I can use the variable &lt;code&gt;name&lt;/code&gt; instead of typing "Sanaipei" again? The &lt;code&gt;print()&lt;/code&gt; function automatically adds spaces between items separated by commas.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;age = 23&lt;/code&gt;&lt;/strong&gt; - Here I'm storing a number without quotes. This is an &lt;strong&gt;integer&lt;/strong&gt; (whole number).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;height_m = 5.213&lt;/code&gt;&lt;/strong&gt; - This stores a decimal number, called a &lt;strong&gt;float&lt;/strong&gt; in Python. Perfect for measurements!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;is_student = False&lt;/code&gt;&lt;/strong&gt; - This is a &lt;strong&gt;boolean&lt;/strong&gt; value. Booleans can only be &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; (notice the capital letters!). They're great for yes/no situations.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My name is Sanaipei
I am 23 years old
My height is 5.213 meters
Am I a student? False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhrx6g5as6eq1wn7ettp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhrx6g5as6eq1wn7ettp.png" alt=" " width="800" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Different Data Types at a Glance
&lt;/h2&gt;

&lt;p&gt;Today I worked with four different data types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;String&lt;/strong&gt; (&lt;code&gt;"Sanaipei"&lt;/code&gt;) - Text wrapped in quotes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integer&lt;/strong&gt; (&lt;code&gt;23&lt;/code&gt;) - Whole numbers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Float&lt;/strong&gt; (&lt;code&gt;5.213&lt;/code&gt;) - Decimal numbers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boolean&lt;/strong&gt; (&lt;code&gt;False&lt;/code&gt;) - True or False values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python is smart enough to figure out what type of data you're storing based on how you write it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways 💡
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variables store data so you can reuse it throughout your code&lt;/li&gt;
&lt;li&gt;Use descriptive names for your variables (like &lt;code&gt;age&lt;/code&gt; instead of &lt;code&gt;a&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Python has different data types: strings, integers, floats, and booleans&lt;/li&gt;
&lt;li&gt;You can print multiple items in one &lt;code&gt;print()&lt;/code&gt; statement by separating them with commas&lt;/li&gt;
&lt;li&gt;Variable names should be lowercase with underscores for spaces (&lt;code&gt;height_m&lt;/code&gt;, not &lt;code&gt;heightM&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow on &lt;strong&gt;Day 3&lt;/strong&gt;, I'll be exploring &lt;strong&gt;type casting&lt;/strong&gt; - how to convert one data type to another. What if I want to turn the number &lt;code&gt;23&lt;/code&gt; into the text &lt;code&gt;"23"&lt;/code&gt;? Stay tuned!&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Connect! 💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have you created your first variables yet?&lt;/li&gt;
&lt;li&gt;What creative variable names have you come up with?&lt;/li&gt;
&lt;li&gt;Any questions about data types?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below! If you're coding along, share what you stored in your variables I'd love to see your creative examples! &lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates on this journey. Day 3 tomorrow! 💪&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy Coding!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>variables</category>
    </item>
    <item>
      <title>Day 1: My First Python Print Statement - 30 Days of Python Challenge</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Thu, 20 Nov 2025 13:59:42 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-1-my-first-python-print-statement-30-days-of-python-challenge-436</link>
      <guid>https://dev.to/sanaipei001/day-1-my-first-python-print-statement-30-days-of-python-challenge-436</guid>
      <description>&lt;h2&gt;
  
  
  Welcome to My Python Journey!
&lt;/h2&gt;

&lt;p&gt;Hey there, fellow coding enthusiasts! Today marks the beginning of my exciting &lt;strong&gt;30 Days of Python Challenge&lt;/strong&gt;, and I'm thrilled to have you join me on this adventure. Whether you're a complete beginner or someone looking to refresh their Python skills, this series is for you!&lt;/p&gt;

&lt;p&gt;I'll be sharing my daily progress, lessons learned, and code snippets as I work through Python fundamentals. My goal? To make Python accessible, fun, and easy to understand for everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 1: The Magic of &lt;code&gt;print()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Today's focus is simple yet powerful: &lt;strong&gt;the print statement&lt;/strong&gt;. Every programming journey starts with a simple "Hello, World!" and today, I'm taking that first step.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;print()&lt;/code&gt; function is your best friend when starting with Python. It's how your program talks to you! Think of it as Python's way of saying, "Hey, look at this!"&lt;/p&gt;

&lt;h3&gt;
  
  
  My Code
&lt;/h3&gt;

&lt;p&gt;Here's what I wrote for Day 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;My name is Sanaipei&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I love Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Data is my love language&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking It Down 🔍
&lt;/h3&gt;

&lt;p&gt;Let me explain what's happening here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print('My name is Sanaipei')&lt;/code&gt;&lt;/strong&gt; - This displays my name on the screen. Notice the single quotes? In Python, you can use either single (&lt;code&gt;'&lt;/code&gt;) or double (&lt;code&gt;"&lt;/code&gt;) quotes for strings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print("I love Python")&lt;/code&gt;&lt;/strong&gt; - Here I'm using double quotes. Both work perfectly! Python doesn't care which you use, as long as you're consistent with opening and closing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;print("Data is my love language")&lt;/code&gt;&lt;/strong&gt; - Because who doesn't love data? 📊&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;When you run this code, you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My name is Sanaipei
I love Python
Data is my love language
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vshaexye9c543jfu17n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vshaexye9c543jfu17n.png" alt=" " width="800" height="36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;print()&lt;/code&gt; is the function used to display output in Python&lt;/li&gt;
&lt;li&gt;You can use both single (&lt;code&gt;'&lt;/code&gt;) and double (&lt;code&gt;"&lt;/code&gt;) quotes for strings&lt;/li&gt;
&lt;li&gt;Each &lt;code&gt;print()&lt;/code&gt; statement displays its content on a new line&lt;/li&gt;
&lt;li&gt;This is your first step in communicating with your computer through code!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;Tomorrow, I'll be diving into *&lt;em&gt;variables *&lt;/em&gt;. We'll explore how to store information and make our code more dynamic and reusable.&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's Connect!💬
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are you also learning Python?&lt;/li&gt;
&lt;li&gt;What was your first programming experience like?&lt;/li&gt;
&lt;li&gt;Any tips or resources you'd recommend?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop a comment below and let's learn together! If you're following along with your own 30 Days of Python challenge, share your progress—I'd love to see it!&lt;/p&gt;

&lt;p&gt;Don't forget to follow me for daily updates on this journey. Let's make these 30 days count! 💪&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy Coding! 🎉&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sanaipei *&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Data Collection Matters</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Sat, 25 Oct 2025 19:24:26 +0000</pubDate>
      <link>https://dev.to/sanaipei001/data-collection-matters-n63</link>
      <guid>https://dev.to/sanaipei001/data-collection-matters-n63</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F01ze555jjos8bsj0ljf1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F01ze555jjos8bsj0ljf1.jpg" alt=" " width="720" height="731"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Day 5:User Input in Python</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Wed, 17 Sep 2025 13:36:43 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-5user-input-in-python-401o</link>
      <guid>https://dev.to/sanaipei001/day-5user-input-in-python-401o</guid>
      <description>&lt;p&gt;On Day 5 of my 100 Days of Python challenge,I explored user input.&lt;br&gt;
This is where Python becomes more interactive instead of just printing things,it can now ask the user for information and respond to it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s the code I wrote today:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Asking for user input
name = input("What is your name? ")
age = input("How old are you? ")
language = input("What programming language are you learning? ")

print("Hello", name + "!")
print("You are", age, "years old.")
print("It's great that you're learning", language + "!")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happened when I ran it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwczf4kouv13b3a6vfijq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwczf4kouv13b3a6vfijq.png" alt=" " width="746" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The input() function:&lt;/p&gt;

&lt;p&gt;-Waits for the user to type something.&lt;/p&gt;

&lt;p&gt;-Returns it as a string (even if you type a number).&lt;/p&gt;

&lt;p&gt;-You can then store it in a variable and use it in your program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub update:&lt;/strong&gt;&lt;br&gt;
I saved my file as day5(user_input).py, then pushed it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add 'day5(user_input).py'
git commit -m "user input"
git push

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Challenge for you&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ask the user for their favorite food,favorite color and favorite hobby.&lt;/p&gt;

&lt;p&gt;Print out a fun sentence using all three answers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your turn:&lt;/strong&gt;&lt;br&gt;
If you could make Python ask YOU one question, what would it be? Drop your answers in the comments I had love to see the creative ones!&lt;/p&gt;

</description>
      <category>python</category>
      <category>usertype</category>
    </item>
    <item>
      <title>Day 4:Type Casting in Python</title>
      <dc:creator>SAINAPEI LENAPUNYA </dc:creator>
      <pubDate>Wed, 17 Sep 2025 13:21:30 +0000</pubDate>
      <link>https://dev.to/sanaipei001/day-4type-casting-in-python-585j</link>
      <guid>https://dev.to/sanaipei001/day-4type-casting-in-python-585j</guid>
      <description>&lt;p&gt;On Day 4 of my Python challenge,I learned about type casting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type casting&lt;/strong&gt; means converting one data type into another for example, changing a number into text, or text into a number (if possible).This is super useful when working with user input or combining different kinds of values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s the code I wrote today:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Integer to float
num_int = 10
num_float = float(num_int)

# Float to integer
decimal_num = 5.9
whole_num = int(decimal_num)

# Number to string
age = 22
age_str = str(age)

# String to integer
num_str = "100"
num_from_str = int(num_str)

print("Integer to float:", num_float)
print("Float to integer:", whole_num)
print("Number to string:", age_str)
print("String to integer:", num_from_str)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happened when I ran it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxczcgkmrkkt9zbzbdhl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxczcgkmrkkt9zbzbdhl.png" alt=" " width="756" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notice how the data type changes when we cast it:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;int → float adds a decimal (10 → 10.0)&lt;/p&gt;

&lt;p&gt;float → int drops the decimal part (5.9 → 5)&lt;/p&gt;

&lt;p&gt;int → str turns numbers into text (22 → "22")&lt;/p&gt;

&lt;p&gt;str → int only works if the string is a number ("100" → 100)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub update:&lt;/strong&gt;&lt;br&gt;
I saved my file as day4(type_casting).py, then pushed it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add 'day4(type_casting).py'
git commit -m "type casting..."
git push

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Challenge for you:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Try converting "3.14" into a float.&lt;/p&gt;

&lt;p&gt;Then convert it into an integer.What result do you get?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your turn:&lt;/strong&gt;&lt;br&gt;
Have you ever had a situation where you needed to convert data types (maybe while coding, or even thinking about real life like changing “22” to 22 😉)?Share your examples in the comments!&lt;/p&gt;

</description>
      <category>python</category>
      <category>typecasting</category>
    </item>
  </channel>
</rss>
