Today is an exercise.
Click here for the last time You will be an engineer in 100 days --Day 26 --Python --Basics of Python language 3
Now, everyone, let's review the lectures so far.
What I've done so far ... How to calculate, how to write a character string, what is an index ... Variables and data types, various operators
I've done some common ideas in other programming languages. This lecture will be a review.
We have prepared a review question, so let's solve it. If you don't know, take a look at the videos and explanations of the lectures so far.
Let's declare a variable of string type
(value is optional,10 characters or more
)
Let's create a string type variable of 5 characters
or more and extract the4th
character.
Create a string type variable and substitute the sentence including line feed
and tab
.
Use the format function
to enter the next sentence,{}
(wave brackets),
Enter any name and output:
`I'm Knights' {0}, my partner's name is a bit dirty, but ... {1}. ``
Create a integer type
variable of 5 digits
and
Convert this to a character string and output it by 0 padding
with 7 digits
.
Put an integer value in two integer type
variables and write a statement to compare the magnitude.
In the next sentence, write a sentence that counts how many words "Urawa" are. `Urawa, Minami-Urawa, Kita-Urawa, Higashi-Urawa, Nishi-Urawa, Musashi-Urawa, Naka-Urawa, Urawa have 7 stations. ``
Write a sentence that displays useless`` 10 times
with line breaks.
Write a statement that calculates 9
to the 9th power
.
Write a sentence that outputs the judgment result, which is larger, 9 to the 20th power
or 20 to the 9th power
.
If you don't get an answer right away, stop the video and think about it.
The trick is what to enter, how to calculate and how to output Let's write while thinking about it.
The answer is below
Let's declare a variable of string type
(value is optional,10 characters or more
)
#To make a string as data, just enclose it in single or double quotes
answer = 'Namamugi raw rice Namamugi, not enough characters'
print(answer)
Namamugi raw rice Namamugi, not enough characters
Let's create a string type variable of 5 characters
or more and extract the4th
character.
#The xth data can be retrieved using the index
#The fourth index value is 3
answer = '123456789'
print(answer[3])
Create a string type variable and substitute the sentence including line feed
and tab
.
#First, prepare a string type variable
#Line breaks and tabs are represented using escape sequences
answer = 'Hello, my name is Masaharu Fukuyama,\n i\t big\It is t.'
print(answer)
Hello, my name is Masaharu Fukuyama, I'm big
Use the format function
to enter the next sentence,{}
(wave brackets),
Enter any name and output:
`I'm Knights' {0}, my partner's name is a bit dirty, but ... {1}. ``
#First, prepare a string type variable
answer = 'I'm knights{0}Well, my partner's name is a bit dirty, but ...{1}is.'
#Insert the value using the format function
print(answer.format('Hanawa','Kotoge'))
I'm Knights' Hanawa, my partner's name is a bit dirty, but ... Kotoge.
Create a integer type
variable of 5 digits
and
Convert this to a character string and output it by 0 padding
with 7 digits
.
#First, prepare a 5-digit integer type variable
answer = 12345
#Convert this to a character string, fill it with 0s in 7 digits, and output it.
#You can use the format function to insert a numeric type into a string.
#0 filling is:Enter the character 0 you want to fill after the colon and enter the number of digits 7.
print({0:07}'.format(answer))
0012345
Put an integer value in two integer type
variables and write a statement to compare the magnitude.
#First, prepare two numbers
a , b = 20 , 30
#Comparison of size is a comparison operator(Relational operator)Use
print(a < b)
print(a > b)
True False
In the next sentence, write a sentence that counts how many words "Urawa" are.
`Urawa, Minami-Urawa, Kita-Urawa, Higashi-Urawa, Nishi-Urawa, Musashi-Urawa, Naka-Urawa, Urawa have 7 stations. ``
#First, prepare a string type variable
answer = 'There are seven stations in Urawa, Minami-Urawa, Kitaurawa, Higashi-Urawa, Nishi-Urawa, Musashi-Urawa, Naka-Urawa, and Urawa.'
#You can count the number of characters with the count function.
print(answer.count('Urawa'))
8
Write a sentence that displays useless`` 10 times
with line breaks.
#asterisk*Can be used to represent repeated characters.
#Line breaks are \ n or\n
print('Useless\n' * 10)
Useless Useless Useless Useless Useless Useless Useless Useless Useless Useless
Write a statement to calculate 9
to the 9th power
,
#Multiplication is one asterisk,Exponentiation is 2 asterisks
print(9 ** 9)
387420489
Write a sentence that outputs the judgment result, which is larger, 9 to the 20th power
or 20 to the 9th power
.
#Compare the size of 9 to the 20th power and 20 to the 9th power with a comparison operator.
print(20 ** 9 < 9**20)
True
So far, only the basics, only the writing part is touched I haven't entered full-scale programming yet.
It may be a little boring, but it will be more interesting from now on. Please continue to enjoy programming. Don't forget to review!
73 days until you become an engineer
Otsu py's HP: http://www.otupy.net/
Youtube: https://www.youtube.com/channel/UCaT7xpeq8n1G_HcJKKSOXMw
Twitter: https://twitter.com/otupython
Recommended Posts