“This is the second day of my participation in the November Gwen Challenge. See details of the event: The last Gwen Challenge 2021”.
@[toc]
preface
This column starts with the “basics” of programming and takes you through “basic algorithms” and the “beauty of Python” and “functions” that are easy and quick to use. Collect “100 Basic Python language questions”, including “real exam questions”, “Basic LeetCode questions”, and add detailed solution ideas and difficulty analysis.
These 100 examples are collected by myself and by myself. They start with “getting started” and end with “advanced”. The “hands-on” plus the solution analysis will give you a “thorough grasp” of the basics of Python
1. Topic description
- Write a program to find the sum of any two numbers taken from the keyboard
- Write a program to find the difference between any two numbers taken from the keyboard
- Write a program to find the product of any given two numbers taken from the keyboard
- Write a program to find the remainder of any given two numbers taken from the keyboard
- Write a program to find the result of dividing given any two numbers taken from the keyboard.
2. Program analysis
A set of templates, can be done
- There’s no point in getting data from the keyboard first
input()
function - Then you need to notice that the input function gets all the data as strings by default
- Note that the result of division requires a time integer
3. Program source code
# 1
a1 = input("Please enter the first number")
b1 = input("Please enter the second number")
print("The sum of two numbers is:",a1+a2)
The second question #
a2 = input("Please enter the first number")
b2 = input("Please enter the second number")
print("The difference between the two numbers is:,a1-a2)
Question # 3
a3 = input("Please enter the first number")
b3 = input("Please enter the second number")
print("The product of two numbers is:",a1*a2)
Question # 4
a4 = input("Please enter the first number")
b4 = input("Please enter the second number")
print("The remainder of two numbers is:",a1%a2)
# 5
a5 = input("Please enter the first number")
b5 = input("Please enter the second number")
print("Two numbers divided by:",a1//a2)
Copy the code
4. Running result
Please enter the first number:1Please enter the second number2The sum of two numbers is:3Please enter the first number:1Please enter the second number:2The difference between the two numbers is: -1Please enter the first number:1Please enter the second number:2The product of two numbers is:2Please enter the first number:1Please enter the second number:2The remainder of the two numbers is:1Please enter the first number:1Please enter the second number:2Two numbers divided by:0
Copy the code
5. Difficulty analysis
- Note that the result of problem 5 is an integer, so use
//
- The input function returns a string value by default, which we need to convert before adding or subtracting
- The dividend cannot be 0
6. Involve knowledge
- Input and output
- Type conversion
- The operator