Categories: Uncategorized

More Worked Examples On Python Basics

Here are 30 challenge exercises covering the topics we covered:

Basic Python Program

  1. Write a Python program to calculate the area of a rectangle given its length and width.
  2. Use Python to calculate the sum of all numbers from 1 to 10.
  3. Write a Python program to convert Celsius to Fahrenheit.

Data Types and Operators

  1. Declare two integer variables, x and y, and assign them values. Then, use the modulus operator to find the remainder of x divided by y.
  2. Write a Python program to concatenate two strings using the + operator.
  3. Use Python to replicate a string three times using the * operator.

Input Function and String Operations

  1. Write a Python program to take a user’s name as input and print out a greeting message.
  2. Use Python to find the length of a user-inputted string.
  3. Write a Python program to take two strings as input and concatenate them.

Comparison Operators

  1. Write a Python program to compare two numbers and print out whether they are equal or not.
  2. Use Python to compare two strings and print out whether they are equal or not.
  3. Write a Python program to check if a given number is greater than 10.

Boolean Operators

  1. Write a Python program to check if a given number is both greater than 5 and less than 10.
  2. Use Python to check if a given string is either “hello” or “world”.
  3. Write a Python program to check if a given number is not equal to 5.

Flow Control and Conditional Statements

  1. Write a Python program to print out the numbers from 1 to 10 using a for loop.
  2. Use Python to print out the numbers from 1 to 10 using a while loop.
  3. Write a Python program to find the sum of all even numbers from 1 to 10 using a for loop.
  4. Use Python to find the sum of all odd numbers from 1 to 10 using a while loop.
  5. Write a Python program to print out the numbers from 1 to 10, skipping the number 5.

Mixing Boolean Operators with Comparison Operators

  1. Write a Python program to check if a given number is both greater than 5 and less than 10, and also not equal to 7.
  2. Use Python to check if a given string is either “hello” or “world”, and also has a length greater than 3.

Conditional Statements

  1. Write a Python program to check if a given number is positive, negative, or zero.
  2. Use Python to check if a given string is empty or not.
  3. Write a Python program to find the maximum of two numbers.

Loops and Conditional Statements

  1. Write a Python program to print out the numbers from 1 to 10, but stop if the number 5 is encountered.
  2. Use Python to print out the numbers from 1 to 10, but skip the number 5.
  3. Write a Python program to find the sum of all numbers from 1 to 10, but stop if the sum exceeds 20.

Advanced Challenges

  1. Write a Python program to simulate a simple calculator that takes in basic arithmetic operations (+, -, *, /) and prints out the result.
  2. Use Python to write a program that takes in a list of numbers and prints out the average, maximum, and minimum values.

smartechlabs

Recent Posts

How to Interface an Ultrasonic Sensor with Arduino

HCSRO4 Ever wondered how bats navigate in total darkness? They use sound waves to "see."…

3 weeks ago

How to Design Linear Power Supply with Grid Utility Alert System

Introduction Have you ever wished your system could tell you when the utility supply comes…

3 weeks ago

IoT-Based Solutions for Detecting Soil Salinity Levels

Introduction IoT soil salinity detection in soil salinity is a silent yet formidable enemy of…

1 month ago

IoT Applications in Tracking Nutrient Levels in Hydroponics

The Internet of Things (IoT) has revolutionized countless industries, and hydroponics is no exception. By…

1 month ago

IoT Smart Irrigation with Soil Erosion Monitoring using NodeMCU, Blynk and Arduino

Introduction https://youtu.be/uaB2waBaWes Imagine having a farm that waters itself automatically and even alerts you when…

1 month ago

IoT Smart Home With Bluetooth Voice Control & Energy Monitoring

The Future of Homes Is Smart https://youtu.be/dxeC41gVSQ4 Imagine walking into your house, saying “lights on”,…

2 months ago

This website uses cookies.