def f1(x): if x > 1 or -1 < x < 1: return (x**2-x)/(x**2-1) elif x == 1: return 1/2 else: return (x-x**2)/(x**2-1) def f2(list1): seen=[] result = [] for element in list1: if element not in seen: seen.append(element) else: if element not in result: result.append(element) return result def f3(astring): result = [] for letter in astring: if letter not in 'aei': result.append(letter) return "".join(result) def f4(): return [i**2 for i in range(1001) if i**2%10==5] def f5(filename): ''' opens a file given by the filename to which the extension csv is added, and then calculates the sum of the values per line to be put into a file with the same filename, but extension txt ''' with open(filename+'.csv') as infile, open(filename+'.txt', 'w') as outfile: for line in infile: suma = 0 numbers=line.strip().split(',') for number in numbers: try: suma += int(number) except: pass print(suma, file = outfile) return def f6(filename): with open(filename) as infile: count = 0 for line in infile: for letter in line: if letter == 'a': count += 1 return count def f7(x): try: float(x) return True except ValueError: return False import random def f8(): secret = random.randint(0,100) while True: x = int(input('guess the number: ')) if x < secret: print('your number is too small') elif x > secret: print('your number is too large') else: print('you got it') return