Hello, Hello, my name is Dream ah , An interesting Python Blogger , Please go easy on me
2021 Blog star of the year TOP100,2021 Blog star of the year TOP5,Python Quality creators in the field , Welcome to cooperate with me ( At the end of the article VX Want to join the learning exchange group or Learning materials welcome +++)Introductory notes : This paradise never lacks genius , Hard work is your final ticket !
Last , May we all shine where we can't see , Let's make progress together
“ Ten thousand times sad , There will still be Dream, I've been waiting for you in the warmest place ”, It's me ! Ha ha ha ~
Preface :
【Python Training camp 】 Is aimed at Python A war created by language learning Brush questions and revel party! If you don't grasp the solid foundation of knowledge , Welcome to this course :Python Public class It's best to use it together ~ If you like, hurry up and subscribe ! If you don't have self-control or motivation to learn and communicate together , Welcome to send a private letter or add my... At the end of the text VX, I will pull you into the learning exchange group , Let's exchange and study together , Group punch in
Title Description
This question is to fill in the blanks , Just calculate the result , Use the output statement in the code to output the filled results .
+-------------------------------------------------+
| |
| H###### #### |
| # # # |
| # # # |
| # #### # # |
| # # # # # |
| ######@### # # |
| # #### # # |
| # # # # # |
| ####@#######@### # # |
| # # # # # |
| T ##### # # # ## |
| # # ### ### ## |
| ################ # # #### |
| # # # # |
| ############## #######@########## |
| # ### |
| ########################### |
+-------------------------------------------------+
Xiao Ming found an old computer in Grandpa's private collection . There's no graphical interface , Can only be programmed with the console . After Xiao Ming's groping , Magically designed the greedy Snake game on the console .
Above , It's a screenshot of the game .
among ,H It means snake head ,TT Indicates snake tail .# Represents the body of a snake ,@ Indicates where the body crosses and overlaps . Can you tell the length of the greedy snake now ?
Actually , Just count # The number of 1, Count out @ The number of counts counts count 2, Plus the head and tail , Plus the head and tail 1$ And we're done .
Count by hand ? Too tired eyes , Smart, why don't you let the computer help ?
The requirement of this question is : Please output the length of the greedy snake in the above figure ?
Operation limit
Maximum operation time :1s
Maximum running memory : 128M
# Time : 2022/2/11 13:06
# File : snake .py
# Author : yes Dream ah !
# WeChat VX : Xu18300396393
# Ten thousand times sad , There will still be Dream, I've been waiting for you in the warmest place !
import os
import sys
# Please enter your code here
a = ''' +-------------------------------------------------+ | | | H###### #### | | # # # | | # # # | | # #### # # | | # # # # # | | ######@### # # | | # #### # # | | # # # # # | | ####@#######@### # # | | # # # # # | | T ##### # # # ## | | # # ### ### ## | | ################ # # #### | | # # # # | | ############## #######@########## | | # ### | | ########################### | +-------------------------------------------------+'''
print(a.count('#')+2+2*a.count('@'))
actually 3 Two single quotes and 3 Double quotes are not often used , But it is useful in some special format strings . Usually, when we define a string in single quotation marks or double quotation marks, we can only write the strings together in one line , If you have to write multiple lines , You have to add a... After each line \ Represents a hyphen , such as :
str1 = "List of name:\
Hua Li\
Chao Deng"
print(str1)
But we can't get the answer we want , In fact, its output is :
List of name: Hua Li Chao Deng
So how do we get the desired output format of one name per line ? This is it. 3 The use of quotation marks :
str1 = '''List of name: Hua Li Chao Deng'''
print(str1)
Get the answer :
List of name:
Hua Li
Chao Deng
Although we can also add... To the string \n Realization :
str1 = "List of name:\nHua Li\nChao Deng"
print(str1)
#List of name:
#Hua Li
#Chao Deng
But it looks a lot messy when typing, doesn't it ? So try to use it in this case 3 Quotation marks , as for 3 Single quotation marks or double quotation marks are the same , Just note that if the string contains single quotation marks, you need to use double quotation marks to define it .
And use 3 Another great use of quotation marks is : add comments of explanations !
Today is my day Python The first of the training camp 18 God , I hope to see the best of you every day
[Python Public class ] Zero base play Python The basic chapter ---- Section 1 :Python The introduction of
[Python Public class ] Zero base play Python Advanced ---- Section 1 :Python File operations in
Come on, let's have a problem swiping Carnival party Well !----【Python Training camp 】
All right. , That's all I want to share with you today
️️️ If you like , Don't be stingy with your one key triple connection ~