Python Practice
name = 'Greedy'condition = 'special'time = 'all of the time' print('{} is {} {}.'.format(name, condition, time)) def calc(x, y, operation): if operation == 'add': return x + y elif operation == 'sub': return x - y elif operation == 'mul': return x * y elif operation == 'div': return x / y running = calc(14, 2, 'div') print(running) running2 = calc(12, 2, 'add') print(running2) print(running + running2) xyz = [] names = ['Mud', 'Jebidiyah', 'Florian', 'Hans'] for i in list(names): xyz.append(i) for i in range(20): xyz.append(i) print(xyz) num_list = [10, 3, 45, 65, 40, 7, 6, 9, 100] def div_five(num): if num % 5 == 0: return True else: return False # So this is basically saying that fives equals any number in the list that passes the# function, i.e. which is divisible by 5. fives = [i for i in num_list if div_five(i)] print(fives)
/Users/mattfassnacht/PycharmProjects/pract3/venv/bin/python /Users/mattfassnacht/PycharmProjects/pract3/jjj.py
Greedy is special all of the time.
7.0
14
21.0
['Mud', 'Jebidiyah', 'Florian', 'Hans', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
[10, 45, 65, 40, 100]
Process finished with exit code 0
Comments