diff --git a/exercises/ex00_hello_world.py b/exercises/ex00_hello_world.py new file mode 100644 index 00000000..fdd3999c --- /dev/null +++ b/exercises/ex00_hello_world.py @@ -0,0 +1,5 @@ +"""My first program for COMP110.""" + +__author__ = "730472840" + +print("Hello, world.") diff --git a/exercises/ex01_chardle.py b/exercises/ex01_chardle.py new file mode 100644 index 00000000..9a4b5d1b --- /dev/null +++ b/exercises/ex01_chardle.py @@ -0,0 +1,68 @@ +"""EX01 - Chardle - A cute step towards Wordle.""" +__author__ = "730472840" + +word: str = input("Enter a 5-character word: ") + +if len(word) < 5: + print("Error: Word must contain 5 characters") + exit() +if len(word) > 5: + print("Error: Word must contain 5 characters") + exit() + +character: str = input("Enter a single character: ") + +if len(character) < 1: + print("Error: Character must be a single character.") + exit() + +if len(character) > 1: + print("Error: Character must be a single character.") + exit() + +print("Searching for " + character + " in " + word) +matching_characters: int = 0 + +if character == word[0]: + print(character + " found at index 0") + matching_characters = matching_characters + 1 + +if character == word[1]: + print(character + " found at index 1") + matching_characters = matching_characters + 1 + +if character == word[2]: + print(character + " found at index 2") + matching_characters = matching_characters + 1 + +if character == word[3]: + print(character + " found at index 3") + matching_characters = matching_characters + 1 + +if character == word[4]: + print(character + " found at index 4") + matching_characters = matching_characters + 1 + + +if matching_characters == 1: + print(str(matching_characters) + " instance of " + character + " found in " + word) + +if matching_characters == 0: + print("No instances of " + character + " found in " + word) + +if matching_characters > 1: + print(str(matching_characters) + " instances of " + character + " found in " + word) + + + + + + + + + + + + + + diff --git a/lessons/00_stored_program.py b/lessons/00_stored_program.py new file mode 100644 index 00000000..afcd08c9 --- /dev/null +++ b/lessons/00_stored_program.py @@ -0,0 +1,6 @@ +"""An example, simple program.""" + +print("Hello, world") +quiz: int = 100 +print(quiz) +print("Goodbye.") diff --git a/lessons/age.py b/lessons/age.py new file mode 100644 index 00000000..382468a3 --- /dev/null +++ b/lessons/age.py @@ -0,0 +1,11 @@ +"""Example memory diagram program""" + +age: int = int(input("What is your age? ")) +year: int = int(input("What year is it? ")) +age_in_2041: int = 2041 - year + age +print("Your age in 2041 will be " + str(age_in_2041)) + +age = age + 1 +year = year + 1 +print("In " + str(year) + ", you'll be " + str(age)) + diff --git a/lessons/conditionals.py b/lessons/conditionals.py new file mode 100644 index 00000000..a06095dc --- /dev/null +++ b/lessons/conditionals.py @@ -0,0 +1,18 @@ +"""An example of conditional (if-else) statements.""" + +SECRET: int = 3 + +print("I'm thinking of a number between 1-5, what is it?") +guess: int = int(input("What is your guess? ")) + +if guess == SECRET: + print("You guessed correctly!!!") + print("Have a wonderful day!!!") +else: + print("Sorry, you guessed incorrectly :(") + if guess > SECRET: + print("You guessed too high!") + else: + print("You guessed too low!") + +print("Game over.") diff --git a/lessons/input.py b/lessons/input.py new file mode 100644 index 00000000..59faf1da --- /dev/null +++ b/lessons/input.py @@ -0,0 +1,5 @@ +"""Demonstrates asking the user for input""" + +user_name: str = input("What is your name? ") +print("Hello, " + user_name + ", good morning!") +print("You are awesome, " + user_name)