current position:Home>Input and output of Python practice

Input and output of Python practice

2022-01-30 22:42:59 Bu Xiaochan

「 This is my participation 11 The fourth of the yuegengwen challenge 2 God , Check out the activity details :2021 One last more challenge 」.

 Insert picture description here

@[toc]

Preface

From 「 Basics 」 Knowledge of programming begins , Take you to understand 「 Basic algorithm 」 as well as 「Python The beauty of 」 And 「 function 」 The convenience and quickness of . collect 「100 example Python Introduction to basic language 」, contain 「 The real exam question 」, 「LeetCode Basic questions 」, And add detailed problem-solving ideas and difficulty analysis .

this 100 The example part is 『 I am 』 collect , Part of what I think , from 『 introduction 』 Start , To 『 Advanced 』 end ,『 Actual operation 』 Add problem solving analysis , Let you 『 To master thoroughly 』Python Language foundation

1. Title Description

  1. Please write a program , Find the sum of any two numbers obtained from the keyboard
  2. Please write a program , Find the difference between any two numbers obtained from the keyboard
  3. Please write a program , Find the product of any two numbers obtained from the keyboard
  4. Please write a program , Find the remainder of any two numbers obtained from the keyboard
  5. Please write a program , Find the result of dividing any two numbers obtained from the keyboard ( The result is required to be an integer )

2. Program analysis

A set of templates , You can finish

  • First, it's no use getting data from the keyboard input() function
  • Then you need to notice ,input The data obtained by the function is a string by default
  • Note that the result of division requires an integer

3. Program source code

#  The first question is 
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 is 
a2 = input(" Please enter the first number ")
b2 = input(" Please enter the second number ")
print(" The difference between the two numbers is :",a1-a2)
#  Third question 
a3 = input(" Please enter the first number ")
b3 = input(" Please enter the second number ")
print(" The product of two numbers is :",a1*a2)
#  Fourth question 
a4 = input(" Please enter the first number ")
b4 = input(" Please enter the second number ")
print(" The remainder of two numbers is :",a1%a2)
#  Fifth question 
a5 = input(" Please enter the first number ")
b5 = input(" Please enter the second number ")
print(" The division of two numbers is :",a1//a2)

 Copy code 

4. Running results

 Please enter the first number :1
 Please enter the second number 2
 The sum of two numbers is : 3
 Please enter the first number :1
 Please enter the second number :2
 The difference between the two numbers is : -1
 Please enter the first number :1
 Please enter the second number :2
 The product of two numbers is : 2
 Please enter the first number :1
 Please enter the second number :2
 The remainder of two numbers is : 1
 Please enter the first number :1
 Please enter the second number :2
 The division of two numbers is : 0
 Copy code 

5. Difficulty analysis

  • Note that the result required in question 5 is an integer , So use //
  • input The value returned by the function defaults to string , We need to transform , Add and subtract
  • The dividend cannot be zero 0

6. Knowledge points involved

  1. Input and output
  2. Type conversion
  3. Operator

Conclusion

copyright notice
author[Bu Xiaochan],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201302242570545.html

Random recommended