Python Homework (Day 1 → Day 3)

Day 1 — Basics (print, input, variables)

1) Greeting Program
Ask the user their name and print: Hello, <name>!
Hint: Use input() and print().
2) Student Introduction App
Take name, age, school, favourite game and print one sentence introducing the student.
Hint: Use input(). Convert age to string with str() if concatenating.
3) Simple Calculator
Input two numbers and print sum, difference, product and quotient.
Hint: Convert inputs to float() before arithmetic.
4) Area of Rectangle
Input length and width and print area.
Hint: Area = length × width; use float().
5) Swap Two Numbers (no third variable)
Swap values of a and b without a temporary variable.
Hint: Use tuple swap: a, b = b, a.
6) Emoji Mood Detector
Ask mood (happy/sad/angry) and print a matching emoji/message.
Hint: Use if/elif/else and normalize input with .lower().
7) Celsius → Fahrenheit
Convert Celsius to Fahrenheit: F = C × 9/5 + 32.
Hint: Use float() for decimals.
8) Add Two Numbers
Read two numbers and print their sum.
Hint: Convert to int() or float().
9) "About Me" Formatter
Create a short About Me using multiple print() lines.
Hint: Use newline \n or multiple prints.
10) Simple Interest Calculator
Compute SI = P * R * T / 100.
Hint: Rate R is percent (e.g., 5 → 5%). Use float().

Day 2 — Types, Casting & Operators

11) Convert String to Int and Add
Take a number as string, convert to int, add 10 and print.
Hint: Use int().
12) Even or Odd Checker
Input a number and print "Even" or "Odd".
Hint: Use % 2.
13) Temperature Converter (C ↔ F)
Let the user choose direction and perform conversion.
Hint: Provide a menu option like '1' or '2' and use float().
14) Marks Calculator
Input 3 marks and compute total and average.
Hint: Use float() and divide by 3.
15) Salary Calculator (HRA & TA)
Compute HRA = 10% and TA = 5% on basic salary and show total.
Hint: hra = basic * 0.10, ta = basic * 0.05.
16) Compound Interest
Compute A = P * (1 + r/100) ** t.
Hint: Use ** for power.
17) Distance Converter (km → m → cm)
Convert kilometers to meters and centimeters.
Hint: 1 km = 1000 m; 1 m = 100 cm.
18) Remainder Finder (%)
Input two numbers and print the remainder (a % b).
Hint: Validate divisor ≠ 0.
19) Floor Division (//)
Show a // b for two integers.
Hint: Floor division returns integer quotient.
20) Convert Float to Int
Input a float and convert to int (truncates).
Hint: int(5.99) → 5.
21) Type Identification
Input anything and print its type using type().
Hint: Raw input() returns string — show conversion example optionally.
22) Concatenate Strings with +
Take two words and print them joined using + and comma in print().
Hint: Use a + " " + b for concatenation.

Day 3 — Decision Making (if / elif / else / logic)

23) Pass / Fail Checker
Input marks and print "Pass" if marks ≥ 35, else "Fail".
Hint: Cast to float() and use if/else.
24) Even / Odd with if-else
Input a number and print whether it's even or odd.
Hint: Use remainder operator %.
25) Age Category
Classify age: ≤12 Child, 13–19 Teen, 20–59 Adult, 60+ Senior.
Hint: Use if/elif/else and check ranges top-to-bottom.
26) Maximum of Two Numbers
Input two numbers and print the larger one.
Hint: Use if a > b or built-in max().
27) Positive / Negative / Zero
Input a number and print whether it is positive, negative or zero.
Hint: Check for zero first (if n == 0).
28) Login Simulation
Ask for username & password and validate against stored values.
Hint: Compare both strings with and.
29) Weather Notifier
Ask if it is raining (yes/no) and advise to carry umbrella or not.
Hint: Normalize input: ans.lower().
30) Divisible by 5 and 11
Check whether a number is divisible by both 5 and 11.
Hint: Use and with modulus.
31) Grade Calculator
Marks → grade using elif ladder: 90+ A, 80+ B, 70+ C, 60+ D, else Fail.
Hint: Check from highest to lowest using elif.
32) Voting Eligibility (Nested if)
Ask age and citizenship (yes/no); eligible if age ≥ 18 and citizen yes.
Hint: Use nested if or combine conditions with and.
33) Traffic Light
Input color (red/yellow/green) and print action (stop/slow/go).
Hint: Use .lower() and if/elif/else.
34) ATM PIN Checker
Ask for PIN and verify (single attempt).
Hint: Treat PIN as string to preserve leading zeros.
35) Number in Range Checker
Check if number is between 1 and 100 inclusive.
Hint: Use chained comparison 1 <= n <= 100.
36) Discount Calculator
If bill ≥ 1000 apply 20% discount otherwise no discount. Print final amount.
Hint: final = bill * 0.8 for 20% off.
37) Scholarship Eligibility
Marks ≥ 85 AND income ≤ 8 → scholarship; elif marks ≥ 60 → admission; else not eligible.
Hint: Use and to combine conditions.

Bonus / Advanced (Optional)

38) Leap Year Checker
Check if a year is leap: divisible by 4 and not by 100 unless divisible by 400.
Hint: Use nested or combined conditions with and/or.
39) Password Strength Simple Checker
Check if password length ≥ 8 and contains at least one digit.
Hint: Use any(ch.isdigit() for ch in pwd).
40) Guess Number (Simple)
Hard-code a secret number and tell if guess is high/low/correct (no loop).
Hint: Use if/elif/else and compare integers.
41) Electricity Bill Slabs
Compute bill with simple slabs (e.g., first 100 units @₹1, next units @₹2).
Hint: Use if/elif and subtract slab units when computing progressive charges.
42) Compare Three Numbers
Input three numbers and print the largest using if (no max()).
Hint: Compare pairwise: first compare a & b then compare winner with c.
Teacher Notes:
  • Ask students to type code (not copy-paste) at least once — typing builds confidence.
  • Encourage changing inputs to see edge cases (zero, negative, large numbers).
  • For extra practice, have students add comments explaining each line using #.
  • To convert this into a Colab notebook, copy each code block into a new cell and run.

Post a Comment

0 Comments