Categories: Uncategorized

Worked Examples On Python By Akachukwu

Here are 30 Python challenge exercises covering the topics we have done so far:

Operators and Expressions

  1. Write a program to calculate the area of a triangle given its base and height using multiplication and division operators.
  2. Write a program that swaps the values of two variables without using a temporary variable.
  3. Evaluate the expression ((10 + 3) * 2 - 4 / 2) and explain the operator precedence used.

Data Types, String Concatenation, and Replication

  1. Create a program that asks for the user’s first and last name and prints them together using string concatenation.
  2. Write a program that replicates a string n times, where n is a user-provided integer.
  3. Convert a floating-point number to an integer and a string. Print the results.

Input and len() Function

  1. Write a program that takes a user’s full name as input and prints the number of characters in their name.
  2. Create a program that asks for the user’s age and calculates the year they were born.
  3. Use the len() function to check the length of a password and display whether it is “Weak”, “Moderate”, or “Strong”.

Comparison Operators

  1. Write a program to check if a given number is greater than, less than, or equal to 50.
  2. Take two inputs from the user and compare if the first input is lexicographically smaller than the second.
  3. Demonstrate the difference between == and = by writing a small program with both.

Boolean Operators

  1. Write a program to check if a number is divisible by both 3 and 5.
  2. Take three user inputs and check if all of them are non-negative numbers using boolean operators.
  3. Combine comparison and boolean operators to check if a number is between 10 and 20 (inclusive).

Flow Control and Conditional Statements

  1. Write a program to display all even numbers between 1 and 50 using a for loop.
  2. Create a while loop that counts down from 10 to 0 and prints “Liftoff!” at the end.
  3. Write a program that prints all numbers from 1 to 20 but skips multiples of 3 using the continue statement.
  4. Use a for loop and break to stop iterating through a list of numbers when you find a negative number.
  5. Write a program to calculate the factorial of a user-provided number using a while loop.

Combining Concepts

  1. Ask the user for their age, and based on the input, print whether they are a “Child”, “Teenager”, “Adult”, or “Senior”.
  2. Write a program that takes a string input and prints “Palindrome” if the string reads the same backward.
  3. Use a for loop to generate a multiplication table for a number input by the user.
  4. Create a program that calculates the sum of all integers between two numbers provided by the user.
  5. Write a program to find the largest and smallest numbers in a list using a for loop.

Bonus Challenges

  1. Create a program that asks for a user’s full name and reverses the order of their name (e.g., “John Doe” becomes “Doe John”).
  2. Write a guessing game where the user has to guess a random number between 1 and 100. Use while loops to keep asking until they guess correctly.
  3. Create a program to check if a user-input string contains both uppercase and lowercase letters.
  4. Write a program to count the vowels in a user-provided string.
  5. Write a program that takes a list of numbers and prints only the prime numbers from the list.

smartechlabs

Recent Posts

AI-Powered Soil Analysis for Precision Nutrient Management: Revolutionizing Agriculture

In the ever-evolving landscape of modern agriculture, artificial intelligence (AI) is emerging as a game-changing…

2 hours ago

IoT Applications in Enhancing Manufacturing Flexibility

The Internet of Things (IoT) is reshaping the way we live, work, and produce goods.…

3 hours ago

AI-Driven Process Optimization in Continuous Manufacturing

Introduction Have you ever wondered how some manufacturing industries consistently deliver high-quality products while minimizing…

3 hours ago

Implementing IoT for Real-Time Monitoring of Livestock Feed Intake

In the ever-evolving landscape of modern agriculture, the integration of Internet of Things (IoT) technology…

4 hours ago

Implementing IoT Solutions for Remote Equipment Diagnostics

Introduction Have you ever imagined diagnosing equipment issues without even being on-site? Welcome to the…

4 hours ago

Leveraging AI for Inventory Management in Smart Manufacturing

In the ever-evolving world of manufacturing, staying competitive means adopting innovative solutions to optimize every…

4 hours ago

This website uses cookies.