You will be an engineer in 100 days --Day 27 --Python --Python Exercise 1

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

Programming exercises

I'm sorry if it doesn't appear

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.

Basic Exercise 1:

Let's declare a variable of string type (value is optional,10 characters or more)

Basic Exercise 2:

Let's create a string type variable of 5 characters or more and extract the4thcharacter.

Basic Exercise 3:

Create a string type variable and substitute the sentence including line feed and tab.

Basic Exercise 4:

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}. ``

Basic Exercise 5:

Create a integer type variable of 5 digits and Convert this to a character string and output it by 0 padding with 7 digits.

Basic Exercise 6:

Put an integer value in two integer type variables and write a statement to compare the magnitude.

Basic Exercise 7:

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. ``

Basic Exercise 8:

Write a sentence that displays useless`` 10 times with line breaks.

Basic Exercise 9:

Write a statement that calculates 9 to the 9th power.

Basic Exercise 10:

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

Answer

Basic Exercise 1: Answer

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

Basic Exercise 2: Answer

Let's create a string type variable of 5 characters or more and extract the4thcharacter.

#The xth data can be retrieved using the index
#The fourth index value is 3
answer = '123456789'
print(answer[3])

Basic Exercise 3: Answer

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

Basic Exercise 4: Answer

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.

Basic Exercise 5: Answer

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

Basic Exercise 6: Answer

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

Basic Exercise 7: Answer

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

Basic Exercise 8: Answer

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

Basic Exercise 9: Answer

Write a statement to calculate 9 to the 9th power,

#Multiplication is one asterisk,Exponentiation is 2 asterisks
print(9 ** 9)

387420489

Basic Exercise 10:

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

Summary

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

Author information

Otsu py's HP: http://www.otupy.net/

Youtube: https://www.youtube.com/channel/UCaT7xpeq8n1G_HcJKKSOXMw

Twitter: https://twitter.com/otupython

Recommended Posts

You will be an engineer in 100 days --Day 27 --Python --Python Exercise 1
You will be an engineer in 100 days --Day 34 --Python --Python Exercise 3
You will be an engineer in 100 days --Day 31 --Python --Python Exercise 2
You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
You will be an engineer in 100 days ――Day 30 ―― Python ―― Basics of Python language 6
You will be an engineer in 100 days ――Day 25 ―― Python ―― Basics of Python language 2
You will be an engineer in 100 days --Day 65 --Programming --Probability 3
You will be an engineer in 100 days --Day 64 --Programming --Probability 2
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
You will be an engineer in 100 days --Day 86 --Database --About Hadoop
You will be an engineer in 100 days ――Day 71 ――Programming ――About scraping 2
You will be an engineer in 100 days ――Day 61 ――Programming ――About exploration
You will be an engineer in 100 days ――Day 74 ――Programming ――About scraping 5
You will be an engineer in 100 days ――Day 73 ――Programming ――About scraping 4
You will be an engineer in 100 days ――Day 75 ――Programming ――About scraping 6
You will be an engineer in 100 days --Day 68 --Programming --About TF-IDF
You will be an engineer in 100 days ――Day 70 ――Programming ――About scraping
You will be an engineer in 100 days ――Day 81 ――Programming ――About machine learning 6
You will be an engineer in 100 days ――Day 82 ――Programming ――About machine learning 7
You will be an engineer in 100 days ――Day 79 ――Programming ――About machine learning 4
You will be an engineer in 100 days ――Day 76 ――Programming ――About machine learning
You will be an engineer in 100 days ――Day 80 ――Programming ――About machine learning 5
You will be an engineer in 100 days ――Day 78 ――Programming ――About machine learning 3
You will be an engineer in 100 days ――Day 84 ――Programming ――About machine learning 9
You will be an engineer in 100 days ――Day 83 ――Programming ――About machine learning 8
You will be an engineer in 100 days ――Day 77 ――Programming ――About machine learning 2
You will be an engineer in 100 days ――Day 85 ――Programming ――About machine learning 10
You will be an engineer in 100 days ――Day 60 ――Programming ――About data structure and sorting algorithm
You become an engineer in 100 days ――Day 67 ――Programming ――About morphological analysis
You become an engineer in 100 days ――Day 66 ――Programming ――About natural language processing
When you get an error in python scraping (requests)
Quicksort an array in Python 3
Will the day come when Python can have an except expression?
Write an HTTP / 2 server in Python
Until you put Python in Docker
Develop an investment algorithm in Python 2
Python in is also an operator
An alternative to `pause` in Python
Become an AI engineer soon! Comprehensive learning of Python / AI / machine learning / deep learning / statistical analysis in a few days!
[Python3] Code that can be used when you want to cut out an image in a specific size
Tkinter could not be imported in Python
If you add sudo on ubuntu, it will be called the default python.
If you write the View decorator in urls.py in Django, the list will be higher.
If an exception occurs in the function, it will be transmitted to the caller 2
If an exception occurs in the function, it will be transmitted to the caller 1