Python Programming Exercises with Solutions - Complete Beginner's Guide

20 Essential Python Exercises for Beginners

Practice Exercises

1. Patient Information

Store patient details in variables:

# Your code here
▶ Solution

2. Simple Calculator

Add two numbers from user input

# Input: 5 and 3 → Output: 8.0
▶ Solution

3. Weight Converter

Convert between kg and lbs

# Input: 68kg → Output: 150lbs
▶ Solution

Complete Solutions

Solution 1: Patient Variables

patient_name = "John Smith"
patient_age = 20
is_new = True

Stores different data types in variables

▲ Back

Solution 2: Calculator

n1 = float(input("First: "))
n2 = float(input("Second: "))
print("Sum:", n1 + n2)

Converts input to numbers before adding

▲ Back

Solution 3: Weight Converter

weight = float(input("Weight: "))
unit = input("(K)g or (L)bs: ").upper()

if unit == "K":
    print(f"{weight}kg = {weight/0.45}lbs")
else:
    print(f"{weight}lbs = {weight*0.45}kg")

Uses conversion formulas with conditionals

▲ Back

4. Temperature Check

Categorize temperature into Hot/Nice/Cold

# Input: 25 → Output: Nice day
▶ Solution

Solution 4: Temperature

temp = float(input("Temperature: "))

if temp > 30:
    print("Hot day")
elif 20 <= temp <= 30:
    print("Nice day")
else:
    print("Cold day")
▲ Back

Python Learning Guide

Master fundamental programming concepts through practical exercises covering variables, conditionals, loops, and data structures.

Posts les plus consultés de ce blog

Les fonctions prédéfinies en Python, les indispensables

Exercices corrigés en Python pour les débutants: entrées, calcul, sorties

Programmer avec Python