Welcome to the exciting world of Python programming! In this tutorial, we'll dive into some challenges that will help you solidify your understanding of Python. 💡
Python is a high-level, interpreted programming language known for its readability and simplicity. It's widely used in various domains like web development, data analysis, machine learning, artificial intelligence, and more.
Before diving into challenges, let's refresh our memory on Python syntax and basic data types:
var_name = value10, -53.14, 0.001"Hello, World!", 'Python is cool'[1, 2, 3], ["apple", "banana", "cherry"](1, 2, 3), ("apple", "banana", "cherry"){ "key": "value", "key2": "value2" }Write a script that accepts two numbers and performs basic operations like addition, subtraction, multiplication, and division.
# Get user input for numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Perform basic operations
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2
# Print results
print(f"Addition: {addition}")
print(f"Subtraction: {subtraction}")
print(f"Multiplication: {multiplication}")
print(f"Division: {division}")Create a simple number guessing game where the computer randomly selects a number between 1 and 10, and the user has to guess it.
import random
# Generate random number between 1 and 10
secret_number = random.randint(1, 10)
# Get user input for guess
guess = int(input("Guess a number between 1 and 10: "))
# Check if guess is correct
if guess == secret_number:
print("Congratulations! You guessed the number correctly.")
else:
print(f"Sorry, the correct number was {secret_number}. Better luck next time!")What is the output of the following code?
Keep practicing, and happy coding! 🚀🚀🚀