Python provides a variety of built-in functions and methods. Among them, I have summarized the ones that I use frequently.
The task of Tommy's blog was very helpful in understanding Python, so I will proceed with this article in the form of a task. If you have any questions, please refer to the detailed explanation at the link.
This article is for the following people.
#Prepare a list to store input values
money_list = []
#Store average amount
average = 0
while True:
#Store input value
money = int(input("Please tell me your money:"))
if money == 0:
break
#Add the amount entered in the list
money_list.append(money)
#Consider division by zero
if len(money_list) !=0:
#Calculate the total value
s = sum(money_list)
#The size stored in the list(Here the number of elements)
n = len(money_list)
#Calculate the average value
average = s / n
print("The average amount of money that everyone has",average,"is.")
alphabet_code= dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"), 0)
words = []
#Enter English words and add the number of characters
while True:
word = input("Please enter and specify English words:")
if word == "":
break
words.append(word)
for letter in word:
if letter in alphabet_code.keys():
#Add if you have a key(If not judged, key error will occur)
alphabet_code[letter] += 1
print('')
print('The words entered are:')
words.sort()
for word in words:
print('・' + word)
print('')
print('The result of the number of alphabet appearances is as follows')
for letter , count in alphabet_code.items():
print("{0}\Number of occurrences of t: {1}Times".format(letter, count))
def fib_func(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib_func(n - 1) + fib_func(n - 2)
target_num = int(input('What number in the Fibonacci sequence do you represent?: ') )
print(fib_func(target_num))
This article is based on Tommy's blog Roadmap article. If you want to know more details or other ways to use it, we recommend learning from the link. Not only the tasks but also the know-how for learning Python from scratch is open to the public, so please take advantage of it!