Freshman python question bank and answers, freshman python final exam questions

Hello everyone, the editor will answer the following questions for you, freshman python fill-in-the-blank question bank, freshman python final short answer questions, let us take a look today!

1. Practice questions about the basics of python language?

1. A brief introduction to the Python language

The Python language is an interpreted, object-oriented programming language and an open source language.

Python is a dynamic class definition language and an emphatically typed language.

Two, the characteristics of the Python language

1. Simple and Advanced

2. Object-oriented

3. Scalability, free and open source

4. Portable, embeddable, rich library

3. The scope of application of the Python language

1. Operating system management

2. Scientific Computing

3. Web application

4. Graphical User Interface (GUI) Development

5. Others, such as game development, etc.

advantage

Simplicity: Python is a language that represents the idea of ​​simplicity. Reading a good Python program feels like reading English. It enables you to focus on solving problems rather than understanding the language itself.

Easy to learn: Python is extremely easy to use, because Python has extremely simple documentation.

Easy to read and maintain: clear and uniform style, mandatory indentation.

Has many uses.

Fast speed: The bottom layer of Python is written in C language, and many standard libraries and third-party libraries are also written in C, which runs very fast.

Free and Open Source: Python is one of FLOSS (Free/Open Source Software). Users are free to distribute copies of this software, read its source code, make changes to it, and use parts of it in new free software. FLOSS is based on the concept of a community sharing knowledge.

2. Freshman python is the answer to the third question, which must be adopted?

a,b,c=map(float,input().split())

v=a*b*c;

s=2*(a*b+a*c+b*c)

print(v,s)

a,b,c=map(float,input().split())

s=(a+b)*c/2

print(s)

x=float(input())

if x<0:

y=2*x-1

elif x<10:

y=2*x+10

elif x<100:

y=2*x+100

else:

y=x**2

print(y)

3. Python topic

This is not a difficult subject, is it? It is very basic content.

Without considering performance and functional robustness, the pseudocode is as follows:

Open the file in r mode:

Read line by line:

Increment row count by 1

A list of rows separated by spaces,

Word count increases list length

The number of characters increases by the sum of the lengths of all elements of the list

output result

There is a file LICENSE.txt in the python installation directory, take it as an example:

linecount = wordcount = charcount = 0

with open('LICENSE.txt', 'r') as f:

for line in f:

linecount += 1

words = line.split(' ')

wordcount += len(words)

charcount += sum(len(_) for _ in words)

print(linecount, wordcount, charcount)

Running output:

605 5258 25385

As for going further, you need to consider some unexpected situations:

Is there a chr(9) that replaces some spaces? It will affect the splitting of the line, and then affect the statistics of the number of words and the number of characters;

Whether there are consecutive spaces, its impact is the same as above;

Besides spaces, are there any characters (such as punctuation marks) that don't count as character data?

To deal with these problems, it is generally necessary to deal with it during or immediately after the process of splitting a line into words. If necessary, "line.split(' ')" can be replaced by a self-written function such as splitbyword(), and the above-mentioned related functions can be realized in it.

4. Freshmen, beginners in Python, how to write code for this question?

  1. The title does not limit the length of the input side must be an integer, it should be changed to a floating point number float

  1. To judge whether a triangle can be formed, it is necessary to ensure that all three sides are positive numbers

  1. Calculate the area when a triangle can be formed, otherwise there may be a situation where the square root sign of a negative number will appear, and an error will be reported

  1. The output is required to retain 1 decimal place, and the output must be formatted

The modified code is as follows:

import math

x = float(input('Please enter the side a of the triangle:')) # The side length may be a floating point number

y = float(input('Please enter the side b of the triangle:'))

z = float(input('Please enter the side c of the triangle:'))

if x>0 and y>0 and z>0 and x+y>z and x+z>y and y+z>x: # Also check whether it is a positive number

p=(x+y+z)/2

s=math.sqrt(p*(px)*(py)*(pz)) # Calculate the area if a triangle can be formed

print('perimeter of triangle=%.1f, area=%.1f' % (x+y+z, s)) # formatted output, keep 1 decimal place

else:

print('Unable to form a triangle')

The above code runs through, but the output test sample is not seen in the picture, please modify the print statement to match the output

5. The vscpp file references a third-party .h file and reports an error that the file path cannot be found

1. File not found

You are all set up and ready to run your analysis, but when you invoke the script from the Minitab command line (or by clicking a button in the toolbar), Minitab displays an error in the Output pane:

Open Phoenix News to view more high-definition pictures

First, make sure you have installed Python and the mtbpy module on your computer according to the documentation.

Usually, setting the default file location for Python scripts resolves this issue. Use the following menu path in Minitab: File > Options and click the "..." button to the right of the first field to browse to where the Python script is saved:

Click OK to save changes. Note that the default file location is also the default folder for saving and opening Minitab files; after saving, Minitab uses this location as the default until you change this option again in this window. After changing it, try running the script again and it should work right away!

If you still get the same message, it's likely that Minitab was unable to find the Python installation. To resolve this issue, you may need to add Python to your system environment variables, a change that may require assistance from your IT team.

2. The Python script does not create any Minitab output

Suppose that after you invoke the script from Minitab, another message appears in the Output pane that you did not expect:

There are two reasons for this message. It may be that the Python script you executed did not include a command to send the results back to Minitab. Alternatively, if the result of the script is an output file (such as .CSV), you may need to manually open the file in Minitab. Whatever the cause, the solution is the same: check the folder that is set as the default file location in Minitab:

In the example above, I want the result of the Python script to be a CSV file. I find the file in the Minitab default file location, then click and drag the file into Minitab with the mouse.

Guess you like

Origin blog.csdn.net/aifans_bert/article/details/129138101
Recommended