Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Faiha Lesson 1, 2020: Python Basics
# Covered so far: # 1. Simple data types # 2. If conditions # 3. While/for loops # 4. Functions # 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 an N-diamond for e.g. N = 5 # 5-shaped diamond # * # *** # ***** # *** # * # 7-shaped diamond # * # *** # ***** # ******* # ***** # *** # * # 3. Design the N-tree, e.g. N = 4, # # @ # @@@ # @@@@@ # @@@@@@@ # ||| # 4. BONUS. For HW 1, 2, 3, write functions for them. # EG: draw_tree(5)
run
|
edit
|
history
|
help
0
Sort word in alphabetical order
Gift_Card Interview SQL Analysis Conducted by Miranda Zhao
Code1
PyLP
homework1
print("Hello, world!")
Name of students
Homework exercise
guesssss
5