tgindex

SortedCoding

описание

Learn to code with clarity and precision

1 278
подписчиков
Охват к подписчикам
47,6%
ERR
Реакции к просмотрам
0,27%
81 на 50 постов
Пересылки к просмотрам
0,27%
79
Постов в день
0,0
всего 63

Где отзываются чаще

доля реакций к просмотрам
  • 6 сент. 2024 г.без подписи0,63%
  • 4 авг. 2025 г.Today, Let’s move on to the next topic in the Python Coding Challenge: 🔹Day 6: Conditionals (if, elif, else) In Python, conditional statements allow your code to make decisions. 💡 What Are Conditionals? They help your program execute certain code blocks only when specific conditions are true. ✅ Syntax : if condition: # Code runs if condition is True elif another_condition: # Runs if previous conditions were False, this one is True else: # Runs if none of the above conditions are True 🧠 Example : age = 18 if age >= 18: print("You’re an adult.") elif age > 13: print("You’re a teenager.") else: print("You’re a child.") Output: You’re an adult. 🎯 Mini Project: Guess the Number Game Let’s build a small game using what we’ve learned so far: Python Code import random number = random.randint(1, 10) guess = int(input("Guess a number between 1 and 10: ")) if guess == number: print("🎉 Correct! You guessed it right.") elif guess < number: print("Too low! Try again.") else: print("Too high! Try again.") print(f"The correct number was: {number}") This project uses: - if, elif, else - User input - Random module React with ❤️ once you’re ready for the quiz0,62%
  • 8 янв.Which operator is used for string repetition?0,55%
  • 8 янв.Today, let's start with the first topic in Python Programming Roadmap: ✅ Python Programming Basics 🐍💻 📌 Step 1: Install Python & VS Code * Download Python 3.11+ from python.org * During install, check ✅ Add Python to PATH * Install VS Code * In VS Code, install the Python extension To check: Open terminal → Type: python --version You should see something like: Python 3.x.x 📌 Step 2: Your First Python Program Create a file: hello.py Paste this code: print("Hello, Python") Run it in terminal: python hello.py 🧠 Python runs code top to bottom 🖨 print() displays output on the screen 📌 Step 3: Variables Variables store values. age = 25 name = "Deepak" height = 5.11 print(age, name, height) ✔️ No need to declare types — Python figures it out ✔️ Use lowercase names with underscores 📌 Step 4: Data Types * int → Whole numbers (e.g., 10) * float → Decimals (e.g., 3.14) * str → Text (e.g., "hello") * bool → True / False To check type: x = 10 print(type(x)) 📌 Step 5: Input & Output Take input from user: python name = input("Enter your name: ") print("Hello", name) Convert string input to number: age = int(input("Enter age: ")) print("Next year you'll be", age + 1) 📌 Step 6: Arithmetic Operators a = 10 b = 3 print(a + b) # Add print(a - b) # Subtract print(a * b) # Multiply print(a / b) # Divide print(a // b) # Floor division print(a % b) # Remainder 📌 Step 7: String Operations first = "Data" second = "Analyst" print(first + " " + second) # Concatenate print("Hi " * 3) # Repeat print(len(first)) # Length 📌 Step 8: Practice Programs 1️⃣ Simple Calculator → Input 2 numbers, show sum, difference, product, division 2️⃣ Temperature Converter → Input Celsius, convert to Fahrenheit F = (C * 9/5) + 32 3️⃣ Age After 5 Years → Input current age, print age after 5 years Here is the detailed code for each project: 📌 Project 1. Simple Calculator num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) print("Addition:", num1 + num2) print("Subtraction:", num1 - num2) print("Multiplication:", num1 * num2) if num2 != 0: print("Division:", num1 / num2) else: print("Division not possible") 📌 Project 2. Temperature Converter (Celsius to Fahrenheit) celsius = float(input("Enter temperature in Celsius: ")) fahrenheit = (celsius * 9 / 5) + 32 print("Temperature in Fahrenheit:", fahrenheit) 📌 Project 3. Age After 5 Years age = int(input("Enter your age: ")) future_age = age + 5 print("Your age after 5 years:", future_age) 🎁 Bonus Practice – Area of a Rectangle length = float(input("Enter length: ")) width = float(input("Enter width: ")) area = length * width print("Area of rectangle:", area) 💡Useful Tips * Run each program * Change input values * Break it on purpose and fix it 🧠 Daily Rule: * Code at least 60 mins * Type every line manually * Don’t copy-paste — build muscle memory I have decided to give some quizzes after this post to test your knowledge0,52%
  • 6 сент. 2024 г.без подписи0,44%
  • 11 янв.Which operator checks if two values are equal?0,43%
  • 11 янв.What is the mistake in this code? age = 17 if age>= 18 print("Adult")0,40%
  • 11 янв.Now, let's move to the next topic in Python Programming Roadmap: ✅ Python Control Flow Part 1: if, elif, else 🧠💻 What is Control Flow? 👉 Your code makes decisions 👉 Runs only when conditions are met * Each condition is True or False * Python checks from top to bottom 🔹 Basic if statement python age = 20 if age >= 18: print("You are eligible to vote") ▶️ Checks if age is 18 or more. Prints "You are eligible to vote" 🔹 if-else example python age = 16 if age >= 18: print("Eligible to vote") else: print("Not eligible") ▶️ Age is 16, so it prints "Not eligible" 🔹 elif for multiple conditions python marks = 72 if marks >= 90: print("Grade A") elif marks >= 75: print("Grade B") elif marks >= 60: print("Grade C") else: print("Fail") ▶️ Marks = 72, so it matches >= 60 and prints "Grade C" 🔹 Comparison Operators python a = 10 b = 20 if a != b: print("Values are different") ▶️ Since 10 ≠ 20, it prints "Values are different" 🔹 Logical Operators python age = 25 has_id = True if age >= 18 and has_id: print("Entry allowed") ▶️ Both conditions are True → prints "Entry allowed" ⚠️ Common Mistakes: * Using = instead of == * Bad indentation * Comparing incompatible data types 📌 Mini Project – Age Category Checker python age = int(input("Enter age: ")) if age < 13: print("Child") elif age <= 19: print("Teen") else: print("Adult") ▶️ Takes age as input and prints the category 📝 Practice Tasks: 1. Check if a number is even or odd 2. Check if number is +ve, -ve, or 0 3. Print the larger of two numbers 4. Check if a year is leap year ✅ Practice Task Solutions – Try it yourself first 👇 1️⃣ Check if a number is even or odd python num = int(input("Enter a number: ")) if num % 2 == 0: print("Even number") else: print("Odd number") ▶️ % gives remainder. If remainder is 0, it's even. 2️⃣ Check if number is positive, negative, or zero python num = float(input("Enter a number: ")) if num > 0: print("Positive number") elif num < 0: print("Negative number") else: print("Zero") ▶️ Uses > and < to check sign of number. 3️⃣ Print the larger of two numbers python a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) if a > b: print("Larger number is:", a) elif b > a: print("Larger number is:", b) else: print("Both are equal") ▶️ Compares a and b and prints the larger one. 4️⃣ Check if a year is leap year python year = int(input("Enter a year: ")) if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap year") else: print("Not a leap year") ▶️ Follows leap year rules: - Divisible by 4 ✅ - But not divisible by 100 ❌ - Unless also divisible by 400 ✅ 📅 Daily Rule: ✅ Code 60 mins ✅ Run every example ✅ Change inputs and observe output0,37%
  • 11 янв.What is the output of this code? a = 5 b = 10 if a> b: print("a is greater") else: print("b is greater")0,36%
  • 6 сент. 2024 г.без подписи0,36%
  • 4 авг. 2025 г.Which one of these is NOT allowed as a key in a dictionary?0,36%
  • 7 сент. 2024 г.без подписи0,33%