Compiler

Python Learning Portal

Review

#part 1
x = 10          
name = "Alice"  
2pi = 3.14       
is Teenager = False
age = 10
print(name, age)

#part 2
name = input("Enter your name: ")
print("Hello", name)

#part 3
age = int(input("Enter your age: "))
print("Next year you will be", age + 1)
print(f"{name} scored {score} points")

    

Python Input, Output, and Variables Exercises

Reinforce your understanding of Python basics with these exercises focusing on input(), print(), variable assignment, and type conversion [2, 5, 13].

1. Personal Information Greeting

Ask the user for their name, age, and country using input(). Print a sentence formatted to display this information back to them, such as: "Hello [name]! You are [age] years old and live in [country]." [2]

2. Simple Arithmetic Calculator

Prompt the user to enter two different numbers. Convert these inputs to integers or floats, calculate their sum, difference, product, and quotient, and print the results [5, 13].

3. Mad Libs Generator

Create a program that asks for a noun, verb, and adjective using separate input() calls. Store these in variables and use an f-string to print a fun sentence incorporating them [4].

4. Temperature Converter

Ask the user to input a temperature in Celsius. Convert it to Fahrenheit using the formula $F = C \times \frac{9}{5} + 32$ and display the result formatted to 2 decimal places [5, 13].

5. Variable Swapper

Assign two different values to variables $a$ and $b$. Without manually changing the code to swap them, write code that swaps their values (so $a$ becomes $b$'s original value and vice versa) and print them [14].

Lessons