Skip to content
View ndumisoluthuli's full-sized avatar

Block or report ndumisoluthuli

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don't include any personal information such as legal names or email addresses. Markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
ndumisoluthuli/README.md
  • 👋 Hi, I’m @ndumisoluthuli
  • 👀 I’m interested in ...
  • 🌱 I’m currently learning ...
  • 💞️ I’m looking to collaborate on ...
  • 📫 How to reach me ...
  • 😄 Pronouns: ...
  • ⚡ Fun fact: ...
  1. Functions Lesson: Defining and Using Functions A function is a reusable block of code that performs a specific task. Here's how to define and use one:
# Function to add two numbers
def add_numbers(a, b):
    return a + b

# Call the function
result = add_numbers(5, 3)
print("Sum:", result)  # Output: Sum: 8

Exercise 1: Square of a Number Write a function that takes a number as input and returns its square.

def square(num):
    return num ** 2

print(square(4))  # Should print 16

Now try:

Test the function with different numbers. Modify it to return the cube of the number instead. Exercise 2: Even or Odd Write a function that checks if a number is even or odd and prints the result.

def check_even_odd(num):
    if num % 2 == 0:
        print(f"{num} is even.")
    else:
        print(f"{num} is odd.")

check_even_odd(7)  # Should print "7 is odd."
  1. Basic Loops Lesson: For Loop Basics A for loop is used to iterate over a sequence like a list, string, or range.
# Example: Print numbers 1 to 5
for i in range(1, 6):
    print(i)

Exercise 1: Even Numbers Write a program that prints all even numbers from 1 to 20 using a loop.

for i in range(1, 21):
    if i % 2 == 0:
        print(i)

Lesson: While Loop Basics A while loop runs as long as a condition is True.

# Example: Countdown
count = 5
while count > 0:
    print(count)
    count -= 1

Exercise 2: User Input Loop Write a program that keeps asking for a word until the user types "exit".

while True:
    word = input("Enter a word (type 'exit' to quit): ")
    if word.lower() == "exit":
        break
    print("You entered:", word)

Practice Challenge: Combine Functions and Loops! Write a function that prints all the multiples of a number up to a given limit.

Example:

def print_multiples(number, limit):
    for i in range(1, limit + 1):
        print(number * i)

print_multiples(3, 5)  # Should print 3, 6, 9, 12, 15

Popular repositories Loading

  1. ndumisoluthuli ndumisoluthuli Public

    Config files for my GitHub profile.

    Python

  2. MyPackage MyPackage Public

    Python

  3. load-shortfall-regression-predict-api load-shortfall-regression-predict-api Public template

    Forked from Explore-AI/load-shortfall-regression-predict-api

    Python

  4. typo3-project typo3-project Public

  5. make make Public

    Forked from b13/make

    Kickstarter CLI tool for various TYPO3 functionalities

    PHP

  6. 100-days-of-code 100-days-of-code Public