Python challenge!
1. Compare Two Numbers: Write a function that takes two integers as input (like the sum
function), but instead prints the larger of the two numbers. If the numbers are equal, it should print
a message saying they are the same. For an extra challenge, modify the function to return the
larger number instead of printing it, then call the function in your main code and print the result
yourself.
2. Compare Three Numbers: Write a function that takes three integers as input and prints the
largest one. (Hint: Use if-elif-else statements to compare them step by step. For extra challenge,
return the largest instead of printing it, and print it outside the function.)
3. Even or Odd Checker: Write a function that takes one integer as input and prints "Even" if it's
even, "Odd" if it's odd. (Hint: Use the modulo operator % like number % 2 == 0 for even. Test
with numbers like 4 and 7.)
4. Simple Greeting: Write a function that takes a name (as a string) and an age (as an integer) as
input, then prints a message like "Hello [name], you are [age] years old!" (Hint: Use string
concatenation with + or f-strings if they're ready, like f"Hello {name}". Introduce strings as text in
quotes.)
5. Multiplication Table: Write a function that takes one integer (like 5) and prints its multiplication
table from 1 to 10 (e.g., "5 x 1 = 5"). (Hint: Use a for loop with range(1, 11) to repeat the printing.
This introduces basic loops.)
6. Sum Up to a Number: Write a function that takes one integer n and prints the sum of all
numbers from 1 to n (e.g., for 3, sum is 6). (Hint: Use a for loop to add numbers one by one, like
total = 0 then total += i in the loop. Builds on looping.)
7. Count to a Number: Write a function that takes an integer and uses a while loop to print
numbers from 1 up to that number. If the number is less than 1, print "Too small!" (Hint: Introduce
while loops with a counter like count = 1; while count <= n: print(count); count += 1. Adds loop
variety and a conditional.)
8. List of Favorites: Write a function that takes a list of three favorite colors (as strings, like ["red",
"blue", "green"]) and prints each one with "I like [color]!". (Hint: Introduce lists with square
brackets, and loop over them with for color in colors:. For extra, ask them to create the list
outside the function.)
9. Find the Smallest in a List: Write a function that takes a list of ve numbers and prints the
smallest one. (Hint: Use a loop to compare each number, starting with the rst as the smallest.
Builds on lists and conditionals; use min() if they want a shortcut later.)
10. Simple Word Reverser: Write a function that takes a word (string) and prints it backward
(e.g., "hello" becomes "olleh"). (Hint: Use a loop to go through the string in reverse with for i in
range(len(word)-1, -1, -1): or slicing like word[::-1]. Introduces string manipulation.)
fi
fi
11. Guess the Secret Number: Write a program (not just a function) that picks a secret number
between 1 and 10, then lets the user guess until they get it right. Print hints like "Too high!" or
"Too low!". (Hint: Use import random for secret = random.randint(1, 10), a while loop for guesses
with input(), and conditionals. This combines everything into a mini-game!)