Question: part1 - short answer questions (6 points each) 1. Assign value 555 to the variable x, write code to calculate x cubed and print out


part1 - short answer questions (6 points each) 1. Assign value 555 to the variable x, write code to calculate x cubed and print out the result. 2. Given a string x, write a one-line command to check if its last character is the same as its second last character. If yes, the code should output "True" 3. Please look at Figure 1. We try to use if statement to test if the given number even or odd. The code is not working as its current form. Please identify one problem with the code. 4. We defined two variables, x = 'Python' and y = '3.0'. Write code to concatenate the two strings while using a space to delimit the result (the result should be 'Python 3.0"), note that there is a space between "Python" and "3.0". 5. Given arbitrary 4 numbers in a list, use Python to generate a list showing the difference between each of the numbers and their mean. For example, if the four values are given in a list x = [1,2,3,4), then the answer should be [-1.5,-0.5,0.5,1.5), where-1.5 is calculated as 1-2.5 (2.5 is the mean of list x). To calculate the mean of a list, you can import a library called "statistics", and use the statistics.mean(some_list) method to calculate the mean. 6. We try to define a function in Figure 2, please identify at least one problems with the code. 7. Given an arbitrary number , write an inline if statement to assign variable y the value 1 if the x is an odd number and divisible by 7 at the same time. Otherwise, assign 0 to variable y. 8. Given two arbitrary lists of the same length, such as x=(1,2,3), and y=[4,5,6], please write codes to "insert" list y into list x. For example, the desired output should be [1,4,2,5,3,6). 9. two ='), , ', . a program tog [yellow,'green''red', white"). Blue is not included since it is not exclusive for both lists it is a commune values are one to list isestaining only exclusive values in both lists. For example, the result should be 10. Given an arbitrary number x, use a while loop to continue adding 1 to x until it is divisible by 5. Then print the latest x value. Figure 1: if x2 -- 0: print('x 18 even') print('x is odd) Figure 2: der function (inputl input2): output - inputl + input2 return (output) part2 - programming questions (10 points each) 1. Please define a function that takes a list as input, and output a sublist containing only the numbers above the median of the original list. For example, the list [1,2,3] has a median of 2, and the output should be (3], because only the number 3 is above the median. Hint: use the statistics package to calculate the median such as statistics.median(x) 2. Suppose we know the budget of a project and its actual spending. Please write a program to compare the budget to the spending. If the budget is greater than the spending print "surplus", if the budget is smaller than the spending print "deficit", otherwise, print "right on budget". When programming, you can assume any budget and deficit values. 3. Write a program to calculate the second smallest number in an arbitrary list. For example, if the list is x = (1,2,3,10,23), then the output should be 2. There are many ways to do it, you will receive full marks as long as the program works. 4. Following the previous question, now define a function that takes a list x and an integer n as inputs, and then return the n-th smallest number in list x. For example, if x=(1,2,3,10,23), and n = 4, then funcx,n)=10 because 10 is the 4th smallest number in x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
