0% found this document useful (0 votes)
6 views

Provide the Python Code for the Fol

Uploaded by

ferroplastics
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Provide the Python Code for the Fol

Uploaded by

ferroplastics
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Provide the python code for the following: 1: Calculate the square of the input

number. If the square is less than 50, exit.

2: Calculate and output the average age of this group of people (keep 2 decimal
places) and the number of males among them(Enter the name, gender, age and other
information of a group of people on the keyboard, separate the information with
spaces, calculate and output the average age of this group of people (keep 2
decimal places) and the number of males among them.).

3:Use string indexing and slicing knowledge to input month numbers and output
English month abbreviations(This is a programming question. Please write the
question description here. For example: This question requires you to input an
integer from 1 to 12 and output the abbreviation of the corresponding month name).

4: jmu-python-determine whether a triangle is formed(Input the three sides of a


triangle and determine whether it can form a triangle. If it can, output yes,
otherwise output no).

5: jmu_python_Greatest common divisor & least common multiple(This question


requires you to input two integers (separated by commas) from the keyboard and
program to find the greatest common divisor and the least common multiple of these
two numbers.

Tip: To find the greatest common divisor, you can use the Euclidean algorithm. The
least common multiple is the product of the two numbers divided by the greatest
common divisor.)

6: jmu-python-determination of repeated elements(As long as one element in a list


appears twice, the list is considered to contain duplicate elements.
Write a function to determine whether a list contains duplicate elements. If so
True, return. Otherwise, return False.
Then use the function to process n lines of strings. Finally, count the number of
lines containing duplicate elements and the number of lines without duplicate
elements.)

7:Sum the numeric elements of a list or tuple(Find the sum of numbers in a list,
the nesting level of the list is not limited to 2 levels

Input format:
Enter a list or tuple on one line

Output format:
Output the sum of numbers in one line)

8:jmu-python-Caesar cipher encryption algorithm(Input format:


Receive two lines of input, the first line is the plaintext to be encrypted, and
the second line is the key k.

Output format:
Output the encrypted ciphertext.)

9:Construct a dictionary from two lists

Input two lines of strings, separated by spaces, and store each line of strings in
list form. Use the element values of the first list as keys and the elements of the
corresponding order in the second list as values to construct a dictionary. After
arranging the keys in ascending order, output a list of all key-value pairs in the
dictionary.
Input format:

Input two lines of strings, separated by spaces and stored as lists.


Output format:

Output a list of dictionary key-value pairs in ascending order of keys

10:Output all permutations

Input an integer n (3<=n<=7), and write a program to output all permutations of


integers 1, 2, ..., n in lexicographic order.
Input format:

Input a positive integer n in one line.


Output format:

Output all permutations from 1 to n in lexicographic order. Each permutation


occupies one line, with no spaces between numbers.

11:Abbreviated journal names

Researchers often submit papers to different journals. However, the formats of


references in different journals are often different. Some journals require that
the journal names published in the references must be abbreviated, otherwise the
manuscript will be rejected directly. Now for a given journal name, it is required
to be abbreviated according to the following rules:
(1) Words with a length of no more than 4 do not need to be abbreviated;
(2) Words with a length of more than 4 only take the first 4 letters, but add "."
after them;
(3) All letters are lowercase.
Input format:

First enter a positive integer T, which represents the number of test data groups,
followed by T groups of test data.
For each test group, enter a string containing uppercase and lowercase letters and
spaces (length not exceeding 85), and the words are composed of several letters,
separated by a space.
Output format:

For each test group, output the abbreviated result on a line, with a space between
words.

12:Enter a number and determine whether it is a daffodil number

Enter an integer and determine whether it is a daffodil number. A daffodil number


is a three-digit integer, and the sum of the cubes of each digit is equal to
itself.
For example, 153 is a daffodil number, 153=1×1×1+5×5×5+3×3×3
Input format:

Enter an integer
Output format:

If the number is a daffodil number, output: "The number is a daffodil number"


If the number is not a daffodil number, output: "The number is not a daffodil
number"
If the number is not a three-digit number, output: "Input error, not a three-digit
number"
13:Use for loop to output the multiplication table
Score 10
Author Hu Guangchun
Organization Xinhuang Dong Autonomous County No. 1 Middle School

I learned the multiplication table in elementary school. Please use nested for loop
to output the multiplication table.
Input format:

No input
Output format:

Use lowercase letter x to represent multiplication sign, input style is as follows


(note spaces and line breaks):
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 9x1=9 9x2=18 9x3=27 9x4=36
9x5=45 9x6=54 9x7=63 9x8=72 9x9=81

14: Anti-prime number

Anti-prime number search. An anti-prime number is a non-palindrome number that is


also a prime number when spelled backwards. For example: 13 and 31 are both prime
numbers and non-palindrome numbers, so 13 and 31 are both anti-primes.
Input format:

Input a positive integer n.


Output format:

Output all anti-primes less than n in order from small to large, with " " after
each number.

15:Baby school report

According to relevant regulations, children who are 6 years old before August 31 of
the year can register for primary school. Check whether the child is eligible for
registration in 2022 based on the ID number. (The eight digits starting from the
seventh are the date of birth)
Input format:

Input ID number
Output format:

Output "yes" or "no"

You might also like