Question

In: Computer Science

Making a program in Python with the following code types. I'm very confused and would love...

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.

Solutions

Expert Solution

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


Related Solutions

I'm very confused on how to complete this code. There are 5 total classes. I have...
I'm very confused on how to complete this code. There are 5 total classes. I have some written but it isn't quite working and the Band class especially is confusing me. I posted the entire thing since the band and manager class refer to the other classes' constructors and thought it would be helpful to post those as well. Person class is a base class: Private variables String firstname, String lastname, int age Constructor has the parameters String firstname, String...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : at least 5 uppercase letters at least 5 lowercase letters at least 5 numbers No more than 20 characters in total I have managed to meet these conditions in individual python files but not in one. Ideally without importing...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : 5 uppercase letters 5 lowercase letters 5 numbers First letter must be capitilized The total characters must be 15 I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still...
What would the Python code be to create the following working program using turtle: -Make 4...
What would the Python code be to create the following working program using turtle: -Make 4 turtles that are YELLOW, and 4 turtles that are GREEN. Create these turtles using one or more lists. -Make the yellow turtles start at a different randomized location somewhere on the left side of the screen within the range of (-100,100) and (0, -100) -Make the green turtles start at a different randomized location somewhere on the right side of the screen within the...
What are the similarities and differences between Mendelian and non-Mendelian inheritance? I'm very confused by what...
What are the similarities and differences between Mendelian and non-Mendelian inheritance? I'm very confused by what im reading online and wanted to know the most significant details that distinguish/relate the two.
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
I'm working on a to-do list program in Python 2. I'm trying to delete an item...
I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue:...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
I'm a little confused regarding types of data & measurement scales for statistics, including: Nominal, Ordinal,...
I'm a little confused regarding types of data & measurement scales for statistics, including: Nominal, Ordinal, Interval and Ratio. If one were to categorize class standing, (1=freshmen, 2=sophomore, 3=junior and 4=Senior) would this be considered Nominal, Ordinal or interval? and why?
So, I'm confused with the S-phase in interphase. Would the number of chromosomes double in number...
So, I'm confused with the S-phase in interphase. Would the number of chromosomes double in number during the S-phase? Wouldn't there be 23 pairs of chromosomes (46 total) before Sphase and 43 pairs (92 chromosomes) after S-phase? Or am I confusing them with the number of chromatids? How many chromosomes would there be during Anaphase I of meiosis, and Telephase II of meiosis (before cytokenesis)?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT