diff --git a/codes.py b/codes.py index f2cb0cb..20331ad 100644 --- a/codes.py +++ b/codes.py @@ -206,4 +206,29 @@ def max_num(num1, num2, num3): print(stars) stars += "*" -print("Loop ended!") \ No newline at end of file +print("Loop ended!") + +# For loop +def replaceVowel(text): + changed_text = "" + for char in text: + if char in "aeiouAEIOU": + changed_text = changed_text + '*' + else: + changed_text = changed_text + char + + return changed_text + +print(replaceVowel("Hello World!")) + + + +# Try Except +try: + input = int(input("Enter a number: ")) + print(input) + result = 10 / 0 +except ZeroDivisionError as err: + print(err) +except ValueError as err: + print(err) diff --git a/info.txt b/info.txt new file mode 100644 index 0000000..1255e75 --- /dev/null +++ b/info.txt @@ -0,0 +1,5 @@ +Earth +Mars +Saturn +Jupiter +I don't know others diff --git a/main.py b/main.py index e69de29..648abc7 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,13 @@ +# Reading from file + +info_file = open("info.txt", "r") # r for read, w for write, a for append, r+ for reading and writing + +# print(info_file.readable()) + +if info_file.readable(): + for info in info_file.readlines(): + print(info) +else: + print("File cannot be read!") + +info_file.close()