Practical Challenges 4

<< Previous: For loopsNext: While loops >>

About the challenges

The challenges below allow you to apply your knowledge of the topics up to this point. Attempt the challenges in a Python IDE of your choice.

Challenge 1: Letter count





word = input("Enter a word: ")
letter = input("Enter a letter: ")
count = 0
for char in word:
    if char == letter:
        count = count + 1
print(f"The letter {letter} appears {count} times in the word {word}.")

Challenge 2: Count between





num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
for i in range(num1,num2+1):
    print(i)

Challenge 3: Average calculator





average_of = int(input("Enter the number of numbers you want to average: "))
total = 0
for i in range(average_of):
    num = int(input("Enter a number: "))
    total = total + num
average = total/average_of
print("The average of these {average_of} numbers is {average}.")
<< Previous: For loopsNext: While loops >>

© All materials created by and copyright S.Goff