본문 바로가기

Python7

Recap (Function Arguments) 레스토랑 테이블 배정 사전 / 테이블 정보 업데이트 function 만들기 preexisting code: tables = { 1: ['Jiho', False], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], } 여기에 새로 손님이 올 때마다 테이블 사전 값을 업데이트하는 function(함수) 추가 def assign_table(table_number, name, vip_status): tables[table_number] = [name, vip_status] 손님 추가하기 #정해진 변수 순서대로 입력하기 assign_table(6, 'Yoni', False) #변수 특정해서 입력하기 (순서는 상관 없음) assign_table(name='Martha', table_numb.. 2022. 8. 14.
[Beginner] Code Challenge: Classes 1. Setting Up Our Robot Create a new class called DriveBot Set up a basic constructor (no parameters needed) Initialize three instance variables within our constructor which all default to 0: motor_speed, direction, and sensor_range class DriveBot: def __init__(self, motor_speed=0, sensor_range=0, direction=0): self.motor_speed = motor_speed self.direction = direction self.sensor_range = sensor_.. 2022. 8. 13.
[Beginner] Code Challenge: Dictionaries 2 1. Word Length Dict (길이 계산) write a function that creates a new dictionary based on a list of strings keys = strings / values = length of each of the words 방법 1. def word_length_dictionary(words): word_lengths = {} for word in words: word_lengths[word] = len(word) return word_lengths 방법 2 - 방법 1 간소화 def word_length_dictionary(words): return {word:len(word) for word in words} 해설지에는 방법1 제시했음 2. Fr.. 2022. 8. 13.