I tried to solve the problem with Python Vol.1

Introduction

From this time, I will solve the problem in AtCoder and regularly check the contents of the problem I'll post a commentary: relaxed:

I don't know how many times it will last or if there is demand, but someone I hope it helps you when you get stuck: kissing_smiling_eyes:

Then, I would like to continue loosely from this time, so thank you: grin:

I will come soon!

I tried to solve 3 questions this time! Now let's explain and explain the problem: stuck_out_tongue_winking_eye: 「9x9」

Problem statement

Takahashi remembered multiplication tables, so he could calculate the product of two integers from 1 to 9 I can do it. No other calculation is possible. Two integers A and B are given. If Takahashi can calculate A × B, the result, if not, -1 instead Please output.

Constraint

1 ≤ A ≤ 20 1 ≤ B ≤ 20 All values being entered are integers.

input

Input is given from standard input in the following format. A,B

output

If Takahashi can calculate A x B, output the result, and if not, output -1.

It was a problem. My answer is ↓.

9x9.py


A , B = map(int, input().split())

if 1 <= A and A <= 9 and 1 <= B and B <= 9:
  print(A * B)
else:
  print(-1)

I'll explain it easily: wink:

First, make two variables in the form of "variable, variable = map (type, input (). Split ())" Input from standard input. Use ".split ()" to separate with spaces You can divide the entered character string and enter it. By the way, ".sprit (" and ")" If you enter it like this, it will be separated by the characters "and": grin:

Then use "if" and "and" to create multiple conditions and if they apply Use "print" to print the result of multiplication of A and B. If the conditions are not met, "-1" is output.

that's all! It's easy: stuck_out_tongue_winking_eye: Let's go next: laughing:

「Curtain」

Problem statement

The horizontal length of the window of Takahashi-kun's house is A, and the horizontal length is B. Two curtains are attached. (The curtain is vertical It is long enough to cover the window. )

Minimize the lateral length of the part of the window that is not hidden by the curtain Close the curtain so that it becomes. At this time, it is hidden by the window curtain Find the total lateral length of the missing parts.

Constraint

1 ≤ A ≤ 100 1 ≤ B ≤ 100 A and B are integers.

input

Input is given from standard input in the following format. A , B

output

Output the total lateral length of the part of the window that is not hidden by the curtain. Output 0 if the window is completely covered by curtains. Each curtain may be longer than the width of the window.

It was a problem. My answer is ↓.

Curtain.py


A , B = map( int, input().split())

if(A - (B * 2) <= 0):
  print(0)
else:
  print(A - (B * 2))

This is first divided into two variables in the form of "variable, variable = map (type, input (). Split ())" Input from standard input. Since it is "split ()", it is input as a space delimiter: point_up: Next, use the "if (condition)" statement to determine whether the curtain will hide or not hide the window. "0" if hidden, non-hidden horizontal length "A-(B * 2)" if not hidden With a "print ()" statement.

that's all. This is also easy: grin: Next is the last of this time! 「Tenki」

Problem statement

A three-day weather forecast is given as a string S of length 3.

When the i (1 ≤ i ≤ 3) letter of S is S, the weather forecast for day i was clear. A C means it was cloudy, and an R means it was raining. Also, the actual weather for 3 days is given as a string T of length 3. When the i (1 ≤ i ≤ 3) letter of T is S, the actual weather on day i was sunny, A C means it was cloudy, and an R means it was raining. Please output how many days the weather forecast hit in 3 days.

Constraint

S and T are strings of length 3. S and T consist only of S, C, R.

input

Input is given from standard input in the following format. S , T

output

Output how many days the weather forecast hit in 3 days.

It was a problem. My answer is ↓.

Tenki.py


S = list(input())
T = list(input())

i = 0
x = 0

while(i < 3):
    if(S[i] == T[i]):
        x = x + 1
    i = i + 1

print(x)

In this problem, first input a string to S and T from standard input with "list (input ())" I was allowed to. Next, the variable "i" is used to compare the characters three times, and the variable "x" is used to compare and count the number of matches. I prepared it. After that, set the condition to "i <1" in the "while (condition)" statement and set "i = i + 1" each time the process is completed. By doing this, the process is repeated 3 times, and the contents of the S [] and T [] arrays are compared in order and match. Process "x = x + 1". After exiting while, you can display the number of matches by displaying x with "print ()". Done: relaxed:

the end

This time I tried to solve three simple problems. To be honest, I think it was too easy for someone who understands programming: joy: I'm going to write loosely like this, so there are things that are difficult to understand and useless writing I would be grateful if you could let me know in the comments, which would be good for my study: blush: Up to here for this time! : blush :: joy :: kissing:

Recommended Posts

I tried to solve the problem with Python Vol.1
I tried to solve the soma cube with python
I tried to solve the ant book beginner's edition with python
I wanted to solve the ABC164 A ~ D problem with Python
The 15th offline real-time I tried to solve the problem of how to write with python
I tried to touch the CSV file with Python
I tried to solve AOJ's number theory with Python
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I wanted to solve the Panasonic Programming Contest 2020 with Python
I tried to divide the file into folders with Python
I wanted to solve ABC160 with Python
Python: I tried the traveling salesman problem
I tried to solve TSP with QAOA
I wanted to solve ABC172 with Python
I tried to solve the virtual machine placement optimization problem (simple version) with blueqat
I tried to solve the shift scheduling problem by various methods
I tried to improve the efficiency of daily work with Python
Try to solve the fizzbuzz problem with Keras
I tried "smoothing" the image with Python + OpenCV
Try to solve the Python class inheritance problem
I wanted to solve NOMURA Contest 2020 with Python
I tried "differentiating" the image with Python + OpenCV
I tried to save the data with discord
Try to solve the man-machine chart with Python
I tried to get CloudWatch data with Python
I tried "binarizing" the image with Python + OpenCV
I want to solve APG4b with Python (Chapter 2)
I tried to implement the traveling salesman problem
I tried fp-growth with python
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!
I tried scraping with Python
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
I tried to express sadness and joy with the stable marriage problem.
How to write offline real time I tried to solve E11 with python
The 16th offline real-time how to write reference problem to solve with Python
I tried to get the authentication code of Qiita API with Python.
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to streamline the standard role of new employees with Python
The 19th offline real-time how to write reference problem to solve with Python
I tried to solve the E qualification problem collection [Chapter 1, 5th question]
I tried gRPC with Python
I tried to solve the inverted pendulum problem (Cart Pole) by Q-learning.
I tried scraping with python
I tried to get the movie information of TMDb API with Python
How to write offline real time I tried to solve E12 with python
I tried to solve the first question of the University of Tokyo 2019 math entrance exam with python sympy
I tried "Implementing a genetic algorithm (GA) in python to solve the traveling salesman problem (TSP)"
I tried to learn the sin function with chainer
Try to solve the programming challenge book with python3
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
The first algorithm to learn with Python: FizzBuzz problem
I tried to draw a route map with Python
I tried to get started with blender python script_Part 02
I tried to implement an artificial perceptron with python
I want to inherit to the back with python dataclass
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to automatically generate a password with Python3
I tried to analyze J League data with Python
I tried hitting the API with echonest's python client