Question

python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a...

python

#Ignore line 2, it is just there to align with zybooks requirements
print("5")
#Create a list with the following numbers and assign it to a variable name: 1,2,3,4,5,6
#Convert the list to a tuple and assign it to a variable name (dirrerent from the list's name)
#Try the following and press the run program button to which ones work and which ones cause errors
#If a statement causes an error, use a # to comment it out
#Add the number 7 to the beggining of the list
#Add the number 7 to the beginning of the tuple
#Append the number 8 to the end of the list
#Append the number 8 to the end of the tuple
#Remove the second element from the list using the pop method
#Remove the second element from the tuple using the pop method
#Get the sum and length of the list and compute the average of the elements in the list
#Get the sum and length of the tuple and compute the average of the elements in the tuple
#Create a tuple with the following numbers and assign it to a new variable name: 2,4,6,8,9
#Convert the tuple to a list and assign it to a new variable name

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: For making it easy to undestand , i first uploaded the parts of the code and with outputs and then submitted the overall code at the end

"HERE IN THE GIVEN STATEMENTS"

"EXCEPT "APPENDING" AND "POPING" FOR TUPLE, ALL THE OTHER STATEMENTS GIVE OUTPUTS"

"appending and poping of tuple doesn't give outputs because "tuples" are immutable"


code for creating a list and converting it into a tuple, adding 7 and appending 8 in a list and tuple

lis=[1,2,3,4,5,6]
tup=tuple(lis)
n=7
lis=[n]+lis
print(lis)
tup=(7,)+tup
print(tup)
lis.append(8)
print(lis)
#tup.append(8)
#we cant use append in a tuple because they are immutable


proof with output:

code for removing second element and finding sum , length , average of list and tuple

lis=[1,2,3,4,5,6]
tup=tuple(lis)
lis.pop(1)
print(lis)
#tup.pop(1)
#we cant use pop in tuples because they are immutable
length=len(lis)
s=0
for l in lis:
    s=l+s
average = s / len(lis)
print(length,s,average)
length=len(tup)
s=0
for l in tup:
    s=l+s
average = s / len(tup)
print(length,s,average)

proof with output:

code for creating a new tuple and converting it into a list and assigning new variables to it:

lis=[1,2,3,4,5,6]
tup=tuple(lis)
newtup=(2,4,6,8,9)
print(newtup)
print(type(newtup))
lis2=list(newtup)
print(lis2)

proof with output:

overall code for the given question:

lis=[1,2,3,4,5,6]
tup=tuple(lis)
n=7
lis=[n]+lis
print(lis)
tup=(7,)+tup
print(tup)
lis.append(8)
print(lis)
#tup.append(8)
#we cant use append in tuple
lis.pop(1)
print(lis)
#tup.pop(1)
#we cant use pop in tuple
length=len(lis)
s=0
for l in lis:
    s=l+s
average = s / len(lis)
print(length,s,average)
length=len(tup)
s=0
for l in tup:
    s=l+s
average = s / len(tup)
print(length,s,average)
newtup=(2,4,6,8,9)
print(newtup)
print(type(newtup))
lis2=list(newtup)
print(lis2)

proof with output:

Add a comment
Know the answer?
Add Answer to:
python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Questions 1. How to create a comment in python? 2. The way to obtain user input...

    Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • Using Swift playground and / or the command line for macOS (open Xcode, create a new...

    Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • Create an application that provides a solution for problem 20.8 In addition to requirements specified in...

    Create an application that provides a solution for problem 20.8 In addition to requirements specified in the description. The class must satisfy the following Default Constructor Two argument constructor for data used to initialize "first" and "second" "toString" method for displaying the "first" and "second" data elements Creates a "Comparator" object (to be used by the sort method; i.e. create an instance of a class that implements the interface [must override "compare" and "equals" methods]) The application must create an...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • Part 1: Using Idle Write a Python Script that Does the Following 1. At the top...

    Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...

  • I really need help with this python programming assignment Program Requirements For part 2, i need...

    I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n):   lst = []   for i in range(1,n+1):     val = float(input('Enter float '+str(i)+': '))     lst.append(val)   return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...

  • Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method...

    Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method  Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6};  Declare an int called largestNum and set it to 0.  Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); }  Write a for loop that prints the array backwards ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT