diff --git a/compare.py b/compare_int.py similarity index 100% rename from compare.py rename to compare_int.py diff --git a/compare_string.py b/compare_string.py new file mode 100644 index 0000000..bfc3c7c --- /dev/null +++ b/compare_string.py @@ -0,0 +1,6 @@ +s = input("s? ") + +t = s.capitalize() + +print(f"s: {s}") +print(f"t: {t}") \ No newline at end of file diff --git a/exit.py b/exit.py new file mode 100644 index 0000000..6a98daf --- /dev/null +++ b/exit.py @@ -0,0 +1,10 @@ +import sys + +if len(sys.argv) < 2: + print("Missing command-line argument!") + sys.exit(1) + +for arg in sys.argv[1:]: + print(f"Hello {arg}!") + +sys.exit(0) \ No newline at end of file diff --git a/greet.py b/greet.py new file mode 100644 index 0000000..34a6b53 --- /dev/null +++ b/greet.py @@ -0,0 +1,7 @@ +from sys import argv + +if len(argv) > 1: + for arg in argv[1:]: + print(f"Hello {arg}!") +else: + print("Hello World!") \ No newline at end of file diff --git a/mario.py b/mario.py new file mode 100644 index 0000000..0ee60c5 --- /dev/null +++ b/mario.py @@ -0,0 +1,15 @@ +def main(): + height = get_height() + for i in range(height): + print("#") + +def get_height(): + while True: + try: + n = int(input("Height?: ")) + except ValueError: + print("ValueError: Not an integer!") + else: + if n > 0: return n + +main() \ No newline at end of file diff --git a/mario2.py b/mario2.py new file mode 100644 index 0000000..a86ad3d --- /dev/null +++ b/mario2.py @@ -0,0 +1,4 @@ +from cs50 import get_int + +width = get_int("Width?: ") +print("?" * width) \ No newline at end of file diff --git a/mario3.py b/mario3.py new file mode 100644 index 0000000..22ceeb7 --- /dev/null +++ b/mario3.py @@ -0,0 +1,7 @@ +from cs50 import get_int + +height = get_int("Height?: ") +width = get_int("Width?: ") + +for i in range(height): + print("#" * width) \ No newline at end of file diff --git a/names.py b/names.py new file mode 100644 index 0000000..760bedc --- /dev/null +++ b/names.py @@ -0,0 +1,12 @@ +import sys + +names = ["Bill", "Charlie", "Fred", "George", "Ginny", "Percy", "Ron"] + +name = input("Name: ") + +if name in names: + print("found") + sys.exit(0) + +print("not found") +sys.exit(1) \ No newline at end of file diff --git a/phonebook.csv b/phonebook.csv new file mode 100644 index 0000000..4ee7730 --- /dev/null +++ b/phonebook.csv @@ -0,0 +1,6 @@ +name,number +David,+1-949-468-2750 +Carter,+1-617-495-1000 +Sascha,+49-163-9681131 +Ina,+49-175-4038108 +Agilent,+49-176-22285334 diff --git a/phonebook.py b/phonebook.py new file mode 100644 index 0000000..804da80 --- /dev/null +++ b/phonebook.py @@ -0,0 +1,9 @@ +import csv + +with open("phonebook.csv", "a") as file: + + name = input("Name: ") + number = input("Number: ") + + writer = csv.DictWriter(file, fieldnames=["name", "number"]) + writer.writerow({"name": name, "number": number}) \ No newline at end of file diff --git a/scores.py b/scores.py new file mode 100644 index 0000000..1c7cce4 --- /dev/null +++ b/scores.py @@ -0,0 +1,12 @@ +from cs50 import get_int + +scores = [] + +while True: + score = get_int("Score?: ") + if score == 0: break + scores.append(score) + +print(f"Scores: {scores}") +average = sum(scores) / len(scores) +print(f"Average: {average}") \ No newline at end of file diff --git a/speech.py b/speech.py new file mode 100644 index 0000000..b327277 --- /dev/null +++ b/speech.py @@ -0,0 +1,6 @@ +import pyttsx3 + +engine = pyttsx3.init() +name = input("Name: ") +engine.say(f"hello {name}!") +engine.runAndWait() \ No newline at end of file diff --git a/swap.py b/swap.py new file mode 100644 index 0000000..6148c5d --- /dev/null +++ b/swap.py @@ -0,0 +1,6 @@ +x = 1 +y = 2 + +print(f"x is {x}, y is {y}") +x, y = y, x +print(f"x is {x}, y is {y}") \ No newline at end of file diff --git a/uppercase.py b/uppercase.py new file mode 100644 index 0000000..8f07f21 --- /dev/null +++ b/uppercase.py @@ -0,0 +1,3 @@ +before = input("Before: ") +after = before.upper() +print(f"After: {after}") \ No newline at end of file