This tutorial introduces fundamental programming structures that form the building blocks of any program. By understanding these constructs, you'll be able to create organized, efficient, and readable code.
name = "Alice" # Declaring a variable 'name' with a string value "Alice"
age = 25 # Declaring a variable 'age' with an integer value 25
name = "Bob" # Assigning a new value "Bob" to the variable 'name'
const
or final
.print("Hello")
name = input("Enter your name: ")
print("Welcome", name)
In this sequence, the code prints "Hello", takes user input, and then prints a welcome message using the input.if-else
statement.
if score >= 90:
print("Excellent!")
elif score >= 80:
print("Good job!")
else:
print("Keep practicing!")
This code checks the score
and prints a message accordingly.for i in range(5): # Looping 5 times
print(i)
count = 0
while count < 10:
print(count)
count += 1 # Incrementing count by 1
numbers = [10, 20, 30, 40]
print(numbers[0]) # Accessing the first element (10)
Functions: Functions perform a specific task and return a value. ``` def add_numbers(a, b): return a + b
sum = add_numbers(5, 10)
print(sum) # Output: 15
- **Procedures:** Procedures perform a specific task but don't return a value.
def print_message():
print("Hello from the procedure!")
print_message() ```
By mastering these fundamental programming constructs, you'll lay a solid foundation for building complex and efficient programs. Remember to practice, experiment, and explore to solidify your understanding!
Create a customised learning path powered by AI — stay focused, track progress, and earn certificates.
Build Your Learning Path →