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
![](https://img.haomeiwen.com/i14319066/ffc5e3222ce5f7f4.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
![](https://img.haomeiwen.com/i14319066/1c47d90e1556056d.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
![](https://img.haomeiwen.com/i14319066/e02db0820b10ca6f.png)
summary:
这道题遇到了一个问题![](https://img.haomeiwen.com/i14319066/44a149b13e9ea393.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]]
![](https://img.haomeiwen.com/i14319066/e6bf4bba0a0283fc.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
![](https://img.haomeiwen.com/i14319066/dc8498e2978771c1.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.
网友评论