본문 바로가기
반응형

전체 글213

Python Multiple return values (Tuple, Dict) # Question:# Write a program that accepts a sentence and calculate the number #of letters and digits.# Suppose the following input is supplied to the program:# hello world! 123# Then, the output should be:# LETTERS 10# DIGITS 3 [Tuple 이용] def countingStr(sentence): countNum = 0 countChar = 0 for i in range(len(sentence)): if((65 2018. 8. 23.
List 자료형의 Join함수 사용하기 Question:Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line. def divisibleSevenNotDivisibleFive(): listOfNumber = "" # Range: 2000 ~ 3200 for i in range(2000, 3201): if((i % 7 == 0) and (i % 5 != 0)): listOfNumber = listOfN.. 2018. 8. 21.
Python Dictionary 자료형 사용해보기 # Make a function lookup_state that, given a US state abbreviation, returns the # state's name.## We've given you a dictionary with abbreviations as keys and state names as values.# It's imported for you here:from US import states## Example:# >>>> lookup_state("NC")# North Carolina def lookup_state(abbreviation): return states.get(abbreviation) # Add print statements to test what your function d.. 2018. 8. 20.
Number of Things Challenge 함수 만들기 # Make a function how_many that, given a list of a number# and a thing name, returns a grmmatically correct sentence# describing the number of things.## >>>> how_many([5, "trinket"])# There are 5 trinkets.# >>>> how_many([1, "king"])# There is 1 king. def how_many(the_list): # Add code here that returns the answer sentence = "" for i in range(len(the_list)): if(i == 0): sentence += str(the_list[.. 2018. 8. 20.
반응형