20192417 Experiment 2 "Python Programming" Experiment Report

20192417 2019-2020-2 "Python Programming" Experiment 2 Report

Course: "Python Programming" Class: 1924 Name: Zhang Jiahua Student ID: 20192417 Experiment Teacher: Wang Zhiqiang Experiment Date: April 11, 2020 Required / Elective: Public Elective

1. Experimental content

  • Design and complete a complete application program, complete operations such as addition, subtraction, multiplication and division, and more functions.
  • Examine the knowledge points of basic grammar, judgment statements, loop statements, logical operations, etc.

2. Experimental process and results

while True:
    x = int(input("输入数字以选择计算器功能,1为加,2为减,3为乘,4为除,5为模运算,6为退出计算器:"))
    if x==6:
        print("已退出计算器")
        break
    a=int(input("请输入第一个数字:"))
    b=int(input("请输入第二个数字:"))
    if x==1:
        print("计算结果为:",a+b)
    if x==2:
        print("计算结果为:",a-b)
    if x==3:
        print("计算结果为:",a*b)
    if x==4:
        print("计算结果为:",a/b)
    if x==5:
        print("计算结果为:",a%b)

3. The problems encountered during the experiment and the resolution process

  • Question 1: It is found that the calculation result cannot be obtained
  • Problem 1 solution: Forgot to convert characters to integers when setting input, just use int () conversion
  • Question 2: After entering 6, it still prompts "Please enter the first number:"
  • Solution to Problem 2: Put the judgment sentence x == 6 before the second and third input

Others (sentiment, thinking, etc.)

Using decision sentences and looping sentences, you can achieve flow control and write many simple and practical small programs

Guess you like

Origin www.cnblogs.com/zjh6/p/12678098.html