In: Computer Science
Making a program in Python with the following code types. I'm very confused and would love the actual code that creates this prompt and a brief explanation. Thanks!
A comment on the top line of your program containing your name.
A comment on the second line containing your section number.
A comment on the third line containing the date.
A comment on the fourth line containing your email address.
A comment with the lab number and purpose of this lab.
Declare a function with one parameter to create a list of X elements (numbering from 1 to X) and then output this list to the screen.
Declare a function with two parameters (X and Y) to create a list of X elements where the elements count by Y. For example, if X = 4 and Y = 3, you should create the following list [3, 6, 9, 12]. You will then need to output this list to the screen.
Declare a function with one parameter X that creates a list of X elements (numbering from 1 to X). You will then remove the last element of the list and print the updated list repeatedly until only one element in the list remains. At this point you will output the remaining list (consisting of the one element) and a message saying that that is the last one.
Include code in your .py file to execute each of the above three functions once each. To execute each function, you should prompt the user for whatever values the function requires, then call the function with the user's values.
Output a message to the user thanking them from using your program that includes your first and last name.
def createList1(X):
num=[]#create empty list
for i in range(X):#run loop from 0 to X-1
num.append(i+1)#append numbers from 1 to X
print(num)#output to screen
def createList2(X,Y):
num=[]#create empty list
for i in range(X):#run loop from 0 to X-1
if i==0:#if this is the first number,
num.append(Y)#append first number
else:#if numbers are in list
num.append(num[-1]+Y)#append new number by adding Y to the last
number
print(num)#output to screen
def showList(X):
num=[]#create empty list
for i in range(X):#run loop from 0 to X-1
num.append(i+1)#append numbers from 1 to X
print(num)
while len(num)>1:
num.pop()#removes the last element
print(num)
print('The last number:',num[0])
X=int(input('Enter X for the first list: '))
createList1(X)
X=int(input('Enter X for the 2nd list: '))
Y=int(input('Enter Y for the 2nd list: '))
createList2(X,Y)
X=int(input('Enter X for the 3rd list: '))
showList(X)
print('Thank you for using this program - FirstName
Lastname')#relace with your name