Skip to content

Commit

Permalink
feat: learn for loop and readfile
Browse files Browse the repository at this point in the history
  • Loading branch information
themaruf committed Aug 9, 2023
1 parent b29cc5d commit f4196a9
Showing 3 changed files with 44 additions and 1 deletion.
27 changes: 26 additions & 1 deletion codes.py
Original file line number Diff line number Diff line change
@@ -206,4 +206,29 @@ def max_num(num1, num2, num3):
print(stars)
stars += "*"

print("Loop ended!")
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)
5 changes: 5 additions & 0 deletions info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Earth
Mars
Saturn
Jupiter
I don't know others
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit f4196a9

Please sign in to comment.