Categories: Uncategorized

Worked Example Exercise Challenge On Python Basics

Here are 30 Python challenge exercises based on the topics we have covered so far:

Basic Python Program: Operators and Expressions

  1. Calculate the area of a rectangle using width and height as inputs.
  2. Swap two variables without using a third variable.
  3. Find the maximum of three numbers using comparison operators.
  4. Convert Celsius to Fahrenheit using the formula $$ F = C \times \frac{9}{5} + 32 $$.

Data Types: Integer, Floating-Point, and String

  1. Create a program that concatenates two strings and prints the result.
  2. Replicate a string a specified number of times based on user input.
  3. Check the type of a variable and print whether it is an integer, float, or string.
  4. Take two integers as input and print their sum, difference, product, and quotient.

Input Function and len() Function

  1. Write a program that takes user input for their name and prints the length of the name.
  2. Ask for a sentence from the user and print the number of words in that sentence.
  3. Create a program that takes a string input and prints it in reverse.

Comparison Operators

  1. Write a program to check if two numbers are equal or not using both == and =.
  2. Create a program that compares two strings and prints whether they are equal or not.
  3. Check if a number is greater than 10 but less than 20 using comparison operators.

Boolean Operators

  1. Write a program that checks if a number is even or odd using boolean operators.
  2. Create an expression that evaluates to true if either of two conditions is met (e.g., age > 18 OR has permission).
  3. Combine comparison operators with boolean operators to check if a number is between 1 and 100.

Flow Control: Conditional Statements

  1. Write a program that prints “Adult” if age is 18 or older, otherwise print “Minor”.
  2. Create a loop that prints numbers from 1 to 10, but skips the number 5 using continue.
  3. Write a program that counts down from 10 to 1, using break to stop at zero.

Loops: For Loops and While Loops

  1. Use a for loop to print all even numbers between 1 and 20.
  2. Write a while loop that sums numbers until the sum exceeds 100.
  3. Create a multiplication table for numbers 1 through 10 using nested loops.

Advanced Challenges

  1. Write a function that takes a list of numbers as input and returns the largest number in the list.
  2. Create a program that checks if a word is a palindrome, ignoring spaces and punctuation.
  3. Implement a simple calculator that performs addition, subtraction, multiplication, and division based on user choice.
  4. Write a function to find the factorial of a number using recursion.

Bonus Challenges

  1. Create a program that generates Fibonacci series up to n terms, where n is provided by the user.
  2. Write code to remove duplicates from a list while maintaining order.
  3. Implement basic error handling in your calculator program to manage division by zero errors gracefully.

smartechlabs

Recent Posts

3D printing filament recycling: How Failed Prints Are Becoming the Next Manufacturing Resource

3D printing filament recycling is no longer a fringe idea discussed only in eco-forums or…

4 days ago

The No-Till Advocate: How AI Helps Plan Cover Crop Rotations for Soil Health

Introduction: Why Is No-Till So Hard to Get Right? No Till Farming Ask any farmer…

4 days ago

The Frost Sentinel: A Low-Cost Sensor Network and AI That Predicts Micro-Frost Events

Frost Sentinel 1 Introduction: Why Do Frost Warnings Still Miss the Damage? If weather apps…

6 days ago

Remote Work Setup 2025: The Complete System for High-Performance Work Anywhere

Remote work setup 2025 is no longer about having a laptop, Wi-Fi, and a quiet…

1 week ago

Decoding Animal Vocalizations: What Your Chickens or Cows Are “Saying” About Their Environment

Introduction: Are Farm Animals Actually Talking to Us? Animal Vocalization If you’ve ever heard a…

1 week ago

Games as Conversation Starters: Titles That Spark Deep Discussion with Friends and Partners

Games as Conversation Starters: Titles That Spark Deep Discussion with Friends and Partners In a…

1 week ago

This website uses cookies.