1. Practical questions:
Design a parking lot fee calculator (charging rules, charge 5 yuan within 2 hours, and add 2 yuan per hour for the excess part),
Requirements are as follows:
(1) The designed program should be able to input the parking time (the unit is hour, and the number of hours input is an integer);
(2) The program can automatically calculate the parking fee according to the input parking time and display it;
(3) The program can be reused.
while True:
n=int(input("Please enter the parking time: "))
if n<=2:
s=5
else:
s=5+(n-2)*2
print("Parking fee",s,"yuan.")
//202103
2. Practical questions:
The user inputs a radius r, and finds the area s and perimeter c of the circle under the radius. Requirements are as follows:
(1) The area and perimeter of the output are kept to two decimal places;
(2) The output format is: "The perimeter of the circle is ** and the area is **";
(3) pi is taken as 3.14;
(4) Use print() to format the output (% method).
r=eval(input("Please enter the radius: "))
pi=3.14
c=2*pi*r
s=pi*r**2
print("The circumference of the circle is %.2f and the area is %.2f."%(c,s))
//202012
1. Practical questions: grades
Write a piece of code that requires the following:
1. After the program starts running, the user is required to input the student's grade (the grade is a positive integer)
2. Enter the grades of one student at a time, and the student grades are from 0 to 100;
3. According to the grade input by the user, the program outputs the corresponding grade according to the grade standard.
4. The grade standard is that the score is less than 60 as a failure, between 60 (inclusive) and 85 (exclusive) is good, and above 85 (inclusive) is excellent.
5. You can repeatedly enter the results to query.
while(True):
n=int(input())
if n<0 or n>100:
print("Incorrect input, the program ends.")
break
elif n>=85:
print("Excellent")
elif n>=60:
print("Good")
else:
print("Failed")
//202012
2. Practical questions: Removing numbers
Requirements are as follows:
1. Write a piece of program code. After the program runs, the user needs to input a string of numbers and letters at will;
2. The program will automatically delete the numbers in the string, and then output a string without numbers (a string of pure letters) or a list (without numbers)
3. The sequence of non-numeric characters required to be output cannot be changed.
a=input("Please enter a string: ")
b=""
for i in a:
if i not in "0123456789":
b+=i
print(b)
//202009
1. Practical questions:
Prompt the user to enter two positive integers, program to find all prime numbers between these two numbers and print the output.
The display format is "XX is a prime number".
n=int(input("Please enter the first integer: "))
m=int(input("Please enter the second integer: "))
for i in range(n,m+1):
t=True
for j in range(2,i//2+1):
if i%j==0:
t=False
break
if t:
print(i,'is a prime number')
//202009
2. Practical questions:
Query area code: Write a program to query the area code entered by the user. When the user enters the area code, the program outputs the corresponding city. Can be queried multiple times.
The test area codes are: 020 Guangzhou, 021 Shanghai, 022 Tianjin, 023 Chongqing, 024 Shenyang, 025 Nanjing
Java beginner's own score query program
txt
0 stars
more than 10% resources
2KB
download
a={'020':'Guangzhou','021':'Shanghai','022':'Tianjin','023':'Chongqing','024':'Shenyang','025':'Nanjing '}
while True:
b = input("Please enter the area code: ")
if b=='1':
print("End query.")
break
elif b in a:
print(a[b])
else:
print("The input is incorrect and cannot be queried.")
//202006B
1. Practical Question: Text Count Recognizer
Requirement: Write a program that can automatically identify the number of times a specific text appears in a certain text. E.g:
a) After the program starts to run, enter a text containing one or more "Python" strings; (hint: please enter a text containing one or more "Python":)
b) Depending on the input string, the program outputs the number of occurrences of Python.
For example: if the input string is "Python is a simple programming language. Python is particularly popular.", then the output is: Number of occurrences of Python: 2
#Reference Code
st=input('Please enter a string:')
count=0
for i in range(len(st)-1):
if st[i:i+6]=='Python':
count+=1
print('The number of occurrences of Python is: ', count)
//202006B
2. Practical questions:
Calculate how much you should pay based on the number of kilometers taken in a taxi. Require:
(1) After the program starts to run, enter a number (integer) of kilometers; (the prompt is: Please enter the kilometers:)
(2) Calculate the fare that should be paid for taking a taxi, and keep two decimal places.
The calculation method is as follows: within 3 kilometers, the charge is 13 yuan; beyond 3 kilometers, 2.3 yuan/km; beyond 15 kilometers, 3.45 yuan/km.
s=int(input('Please enter the number of kilometers:'))
f=0.0
if s>15:
f+=(s-15)*3.45
s=15
if s>3:
f+=(s-3)*2.3
s=3
f+=13
print('%.2f'%(f))
//202006
1. Practical questions: Converting numbers to Chinese characters
The user inputs a number between 1 and 9 (including 1 and 9), and the program outputs the corresponding Chinese character.
Such as input 2, the program output "two". Repeatable query.
s='0123456789'
while(True):
n=int(input('Please enter a number:'))
if n>=1 and n<=9:
print(s[n])
else:
print('The input does not conform to the rules')
break
//202006
2. Practical questions:
Suppose the scores of 10 judges are 99, 80, 86, 89, 94, 92, 75, 87, 86, 95. Now we need to use Python language for programming: remove the highest score, remove the lowest score, calculate the average score, and print it out.
The print format is:
Remove a maximum score: XX points, remove a minimum score: XX points, the final score is: XX points.
ls=[99,80,86,89,94,92,75,87,86,95]
maxn=max(ls)
ls.remove(maxn)
minn=min(ls)
ls.remove(minn)
sumn=sum(ls)
print("Remove a highest score: {} points, remove a lowest score: {} points, and the final score is: {} points.".format(maxn,minn,sumn/8))