.
This commit is contained in:
4
CS1032/practical-2023-11-15/decomment.py
Normal file
4
CS1032/practical-2023-11-15/decomment.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import sys
|
||||
|
||||
for line in sys.stdin:
|
||||
print(line.split('#')[0].rstrip())
|
||||
11
CS1032/practical-2023-11-15/pass.py
Normal file
11
CS1032/practical-2023-11-15/pass.py
Normal file
@@ -0,0 +1,11 @@
|
||||
#! /usr/bin/env python3
|
||||
import sys, random
|
||||
|
||||
with open(sys.argv[1]) as words_f:
|
||||
words = [word for line in words_f if 3 <= len(word := line.strip()) < 10 and word.lower() == word]
|
||||
|
||||
pair = []
|
||||
while not 8 <= sum(map(len, pair)) <= 10:
|
||||
pair = random.choices(words, k=2)
|
||||
|
||||
print(''.join(w.title() for w in pair))
|
||||
6
CS1032/practical-2023-11-15/redact.py
Normal file
6
CS1032/practical-2023-11-15/redact.py
Normal file
@@ -0,0 +1,6 @@
|
||||
#! /usr/bin/env python3
|
||||
import sys, re
|
||||
redacted = re.compile(f"({'|'.join([s.strip() for s in open(sys.argv[1])])})")
|
||||
|
||||
for line in sys.stdin:
|
||||
print(redacted.sub(lambda m: '*' * len(m.group(0)), line), end='')
|
||||
9
CS1032/practical-2023-11-15/sum.py
Normal file
9
CS1032/practical-2023-11-15/sum.py
Normal file
@@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
sum = 0
|
||||
while True:
|
||||
i = input(f"[{sum:g}]: ")
|
||||
if not i: break
|
||||
try:
|
||||
sum += float(i)
|
||||
except ValueError: print(f"\t'{i}' is not a number")
|
||||
Reference in New Issue
Block a user