More Worked Examples On Python Basics
Here are 30 challenge exercises covering the topics we covered:
Basic Python Program
- Write a Python program to calculate the area of a rectangle given its length and width.
- Use Python to calculate the sum of all numbers from 1 to 10.
- Write a Python program to convert Celsius to Fahrenheit.
Data Types and Operators
- 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. - Write a Python program to concatenate two strings using the
+ operator. - Use Python to replicate a string three times using the
* operator.
Input Function and String Operations
- Write a Python program to take a user’s name as input and print out a greeting message.
- Use Python to find the length of a user-inputted string.
- Write a Python program to take two strings as input and concatenate them.
Comparison Operators
- Write a Python program to compare two numbers and print out whether they are equal or not.
- Use Python to compare two strings and print out whether they are equal or not.
- Write a Python program to check if a given number is greater than 10.
Boolean Operators
- Write a Python program to check if a given number is both greater than 5 and less than 10.
- Use Python to check if a given string is either “hello” or “world”.
- Write a Python program to check if a given number is not equal to 5.
Flow Control and Conditional Statements
- Write a Python program to print out the numbers from 1 to 10 using a for loop.
- Use Python to print out the numbers from 1 to 10 using a while loop.
- Write a Python program to find the sum of all even numbers from 1 to 10 using a for loop.
- Use Python to find the sum of all odd numbers from 1 to 10 using a while loop.
- Write a Python program to print out the numbers from 1 to 10, skipping the number 5.
Mixing Boolean Operators with Comparison Operators
- 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.
- Use Python to check if a given string is either “hello” or “world”, and also has a length greater than 3.
Conditional Statements
- Write a Python program to check if a given number is positive, negative, or zero.
- Use Python to check if a given string is empty or not.
- Write a Python program to find the maximum of two numbers.
Loops and Conditional Statements
- Write a Python program to print out the numbers from 1 to 10, but stop if the number 5 is encountered.
- Use Python to print out the numbers from 1 to 10, but skip the number 5.
- Write a Python program to find the sum of all numbers from 1 to 10, but stop if the sum exceeds 20.
Advanced Challenges
- Write a Python program to simulate a simple calculator that takes in basic arithmetic operations (+, -, *, /) and prints out the result.
- Use Python to write a program that takes in a list of numbers and prints out the average, maximum, and minimum values.
Recent Posts
AI Upskilling Workshops for Professionals in Non-Tech Fields: Bridging the Gap Between AI and Daily…
Introduction: Is There an AI That Can Summarize What’s Happening in My Local Community? If…
Is There Really an AI That Can Handle Automating Technical Documentation Translation? Have you ever…
Introduction: Why Do Old Games Still Feel Better Than New Ones? Have you ever picked…
Introduction: Do You Really Need Expensive Tech to Get Efficient Solar Power? When most people…
Have you ever opened a technical manual, engineering specification, or software document and thought, “This…
This website uses cookies.