Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
homework1
# Covered so far: # 1. Simple data types # 2. If conditions # 3. While/for loops # 4. Functions # 5. # def function_name(arg1, arg2, ..., argN): # do_something def add(input_list): total_sum = 0 for each_num in input_list: total_sum = total_sum + each_num return (total_sum) def multiply(input_list): multi_each = 1 for each_num in input_list: multi_each = multi_each* each_num return (multi_each) # MATLAB syntax # function [output] = function_name(arg1, arg2, ... , argN) # # end # total_sum each_num total_sum + each_num # 0 3 = 3 -> total_sum # 3 2 = 5 -> total_sum # 5 45 = 50 -> total_sum # Write a function that adds two numbers x_list = [7, 0] c=add(x_list) print (c) d = multiply([3, 1]) print(d) # Fibonacci sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... ] # Homework: # 1. Print the Fibonacci sequence up to N # 2. Print a N-diamond for e.g. N = 5 # 5-shaped diamond # * # *** # ***** # *** # * # 7-shaped diamond # * # *** # ***** # ******* # ***** # *** # *
run
|
edit
|
history
|
help
0
My name
ip2cidr
Python_Hello_World
Helloworld
lesson 6 final
Lab_III_3_24_11_2020
HW Descending order Insertion Sort
Ваня и забор
StringManipulation
Simple calculator