diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2020-01-22 14:43:35 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2020-01-22 14:43:35 +0100 |
| commit | 6319633122e8cc12786361a71b942381f80f9f0a (patch) | |
| tree | 38993b3895a31729906a86168e9590b07fc3f930 /upg1.py | |
| download | tdde44-6319633122e8cc12786361a71b942381f80f9f0a.tar.gz | |
Do lab1
Diffstat (limited to 'upg1.py')
| -rw-r--r-- | upg1.py | 148 |
1 files changed, 148 insertions, 0 deletions
@@ -0,0 +1,148 @@ +import math + + +def return_five(): + return "five" + + +def print_five(): + print("five") + + +def add_strings(): + return "hej" + "san" + + +def use_the_var(): + value = 5 + return value * 5 + + +def use_the_arg(a_string): + print(a_string) + return a_string + + +def to_string(a_value): + return str(a_value) + + +def to_integer(a_value): + return int(a_value) + + +def to_float(a_value): + return float(a_value) + + +def to_any_type(a_value, a_type): + return a_type(a_value) + + +def print_type(a_value): + print(type(a_value)) + + +def subtract(value1, value2): + return value1 - value2 + + +def split_bill(amount, number_of_people): + print(amount / number_of_people) + return amount / number_of_people + + +def round_up(value): + return math.ceil(value) + + +def round_down(value): + return math.floor(value) + + +def celsius_to_fahrenheit(value): + return value * 9/5 + 32 + + +def fahrenheit_to_celsius(value): + return (value - 32) * 5/9 + + +def pythagoras(x, y): + return math.sqrt(x ** 2 + y ** 2) + + +def second_in_list(values): + return values[1] + +def last_in_list(values): + return values[-1] + +def second_last_in_list(values): + return values[-2] + +def n_in_list(values, n): + return values[n] + +def three_first_in_list(values): + return values[:3] + +def three_last_in_list(values): + return values[-3:] + +def but_five_last_in_list(values): + return values[:-5] + +def every_other_in_list(values): + return values[::2] + +def two_around_n_in_list(values, n): + return values[n-2:n+3] + +def new_list_with_n(values, a_value): + return values + [a_value] + +def append_n_to_list(values, a_value): + values.append(a_value) + return values + +def insert_4_on_pos_3(values): + values.insert(3, 4) + return values + +def extend_vals_to_list(values1, values2): + values1.extend(values2) + return values1 + +def remove_from_third_in_list(values): + del values[2:] + return values + +def concatenate_lists(values1, values2): + return values1 + values2 + +import random +def select_random(values): + return random.choice(values) + +def concatenate_strings(string1, string2): + return string1 + string2 + +def use_the_linebreak(): + print("rad 1\nrad 2") + return "rad 1\nrad 2" + +def generate_pokemon_name(prefixes, suffixes): + return concatenate_strings(select_random(prefixes), select_random(suffixes)) + +def first_word(s): + return s.split(" ")[0] + +def join_list(vals): + return ":".join(vals) + +def remove_spaces(s): + return s.rstrip() + +def get_characters(s, pos, num_of_chars): + return s[pos:pos+num_of_chars] |
