-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_file_handling.asp file handling | ||
import os | ||
|
||
print('Question: Find money owed to friends') | ||
|
||
def update_file(name, amount): | ||
path = 'tmp/' + name + '.txt' | ||
# get current amount | ||
reader = open(path, 'r') | ||
current_amount = int('0'+reader.read()) | ||
# write the new amount | ||
writer = open(path, 'w') | ||
writer.write(str(current_amount + amount)) | ||
|
||
names = ['raj', 'riya', 'raj'] | ||
amounts = [1000, 200, 300] | ||
|
||
# # first make empty files for all :) | ||
for name in names: | ||
open('tmp/'+name+'.txt','w') | ||
|
||
for name, amount in zip(names, amounts): | ||
update_file(name, amount) | ||
|
||
print('Made the files with total debts') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
# Required concepts: https://www.w3schools.com/python/python_intro.asp map, filter, lambda | ||
# Required concepts: https://www.w3schools.com/python/python_file_handling.asp file handling | ||
import os | ||
|
||
print('Question: prime numbers in list,') | ||
print('Question: Find money owed to friends') | ||
|
||
def check_prime(num): | ||
for i in range(2,num): | ||
if num == 1: | ||
return False | ||
if num%i == 0: | ||
# you found a factor of num! | ||
return False | ||
# you didn't find any multiple, you're prime | ||
return True | ||
|
||
li = [2,3,4,5,6,7,8,9] | ||
print(li) | ||
def update_file(name, amount): | ||
path = 'tmp/' + name + '.txt' | ||
# get current amount | ||
reader = open(path, 'r') | ||
current_amount = int('0'+reader.read()) | ||
# write the new amount | ||
writer = open(path, 'w') | ||
writer.write(str(current_amount + amount)) | ||
|
||
primes = filter(check_prime,li) | ||
|
||
print(list(primes)) | ||
names = ['raj', 'riya', 'raj'] | ||
amounts = [1000, 200, 300] | ||
|
||
# # first make empty files for all :) | ||
for name in names: | ||
open('tmp/'+name+'.txt','w') | ||
|
||
for name, amount in zip(names, amounts): | ||
update_file(name, amount) | ||
|
||
print('Made the files with total debts') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
200 |