Python Rehabilitation Week 1 Review

Today I completed the exam for the first week of content, learned the turtle content for the second week, took the exam, and studied the daily improvement examples for the third week.Python Rehabilitation Week 1 ReviewAmong them, the second programming problem is worth noting.Python Rehabilitation Week 1 ReviewIn the input calculation expression, there are numbers and operators, and the input type is a string. Therefore, we should slice different types of elements and integrate them into a mathematical expression. First, locate the position of the operator, then slice the numbers before and after it, combine them into a new string expression, and finally use the eval function to convert the data type for calculation.As I wrote this, I suddenly thought that the initial input was also a string of characters, and it was cumbersome to slice out the numbers and operators and then combine them. So why not just use eval directly… I quickly tried it, and then everything fell apart.Python Rehabilitation Week 1 ReviewI asked Teacher D.Python Rehabilitation Week 1 ReviewTeacher D suggested that it is very likely that the input contains spaces, so we need to exclude spaces, for example, 1 +10 0, and then slice again, etc. I ran Teacher D’s program, and it threw an error…I’ll modify Teacher D’s program tomorrow.Python Rehabilitation Week 1 ReviewThe turtle exercises are all very simple.

Leave a Comment