반응형 <개인공부> - IT/[Python]38 What does if __name__ == “__main__”: do? 궁금해서 찾아보았는데 과제하는데 도움이 될 것 같아서 공부삼아 기록한다. When your script is run by passing it as a command to the Python interpreter, python myscript.py all of the code that is at indentation level 0 gets executed. Functions and classes that are defined are, well, defined, but none of their code gets run. Unlike other languages, there's no main() function that gets run automatically - the main() function is im.. 2018. 9. 15. 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. 이전 1 ··· 5 6 7 8 9 10 다음 반응형