美文网首页
Python 100练习题 Day2

Python 100练习题 Day2

作者: P酱不想说话 | 来源:发表于2021-03-16 00:59 被阅读0次

Question 4

Question: Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.Suppose the following input is supplied to the program:

34,67,55,33,12,98 Then, the output should be:

['34', '67', '55', '33', '12', '98'] ('34', '67', '55', '33', '12', '98')

Hints: In case of input data being supplied to the question, it should be assumed to be a console input.tuple() method can convert list to tuple


image.png

Question 5

Question: Define a class which has at least two methods:

getString: to get a string from console input printString: to print the string in upper case. Also please include simple test function to test the class methods.

Hints: Use init method to construct some parameters


image.png

Question 6

Question: Write a program that calculates and prints the value according to the given formula:

Q = Square root of [(2xCxD)/H]

Following are the fixed values of C and H:

C is 50. H is 30.

D is the variable whose values should be input to your program in a comma-separated sequence.For example Let us assume the following comma separated input sequence is given to the program:

100,150,180 The output of the program should be:

18,22,24


image.png

summary:

这道题遇到了一个问题 image.png

主要原因是遇到这种情况,原因处在for循环的时候循环的索引应该要注意,所以在此处改成利用列表长度的方式去进行for循环

Question 7

Question: _Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i _ j.*

Note: i=0,1.., X-1; j=0,1,¡­Y-1. Suppose the following inputs are given to the program: 3,5

Then, the output of the program should be:

[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

image.png

summary:

生成一个矩阵这种问题,最简单直接的方式是使用numpy,不想记忆别的方式、简单直接

Question 8

Question: Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.

Suppose the following input is supplied to the program:

without,hello,bag,world Then, the output should be:
bag,hello,without,world


image.png

Question 9 Question: Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.

Suppose the following input is supplied to the program:

Hello world Practice makes perfect Then, the output should be:

HELLO WORLD PRACTICE MAKES PERFECT Hints: In case of input data being supplied to the question, it should be assumed to be a console input.

相关文章

网友评论

      本文标题:Python 100练习题 Day2

      本文链接:https://www.haomeiwen.com/subject/afkrcltx.html