Chat with us, powered by LiveChat Grossmont College Python Codes Programming Questions - Credence Writers
+1(978)310-4246 [email protected]

Description

# Question 1 (10pts)
# Given a list containing strings and numbers(ints and floats), print the
# length of each element.
# e.g. x = [‘a’, 2, ‘abc’, 1234, 23.4]
# output for example(note that its all in oneline): 1, 3, 4, 4
# HINT: remember print() has an optional parameter that lets you replace
# decide what gets printed at the end of each print statement
pass
# Question 2 (10pts)
# Given a list of lists of integers, reverse the list entirely.
# Use list comprehension to produce a new list totally reversed and
# then print the totally reversed.
# e.g. x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# > [[9, 8, 7], [6, 5, 4], [3, 2 1]]
# HINT: Use dir() and help() to see what methods are available for a list
pass
# Question 3 (10pts)
# Define conditional logic (if) for the following scenario:
# Given 2 variables, a and b, you can assume that they will point to
integer objects
# Print “Not equal or remainder is non-zero” when a and b are not the
same
# or when a divided by b has a any remainder other than zero Otherwise
print “Equal or zero remainder”
# e.g.
# e.g.
# e.g.
# e.g.
pass
a
a
a
a
=
=
=
=
4,
4,
4,
4,
b
b
b
b
=
=
=
=
4
2
1
3
=>
=>
=>
=>
“Equal or zero remainder”
“Equal or zero remainder”
“Equal or zero remainder”
“Not equal or remainder is greater than zero”
# Question 4 (10pts)
# Given a sequence (e.g. strings and lists), return(meaning print) the
middle
# two elements using list slicing. Assume sequence has a length of 2 or
# greater; if size is odd see the first example.
# a = ‘abcdefg’ > ‘cd’
# a = ‘ae’ > ‘ae’
# a = ‘abcdef’ > ‘cd’
pass
#
#
#
#
#
Question 5 (10pts)
Given a list of random integers, double the size of the list of random
integers, then sort the list and print it.
HINT: use dir() and help() to find built-in function
HINT: you can double the size of the list however you want, as long as
# you reference the size of l when doubling. Meaning, don’t simply
# manually add 5 items, if I were to change the 5 in range(5), the code
# you supply should still work.
# e.g. x = [random.randint[0, 40] for x in range(10)] // this is creating
a list by generating a random integer
# between 0 and 40 range(40) number of times
import random
l = [random.randint(0, 40) for x in range(5)]
pass
# Question 6 (15pts)
# Write the following logic into a while loop
# given l1, iterate through l1 printing every item.
# If an item happens to be a list, iterate through that given item
# and print all its contents preceded by a “-” (do not include quotes).
# If you encounter any string in the outer most list that includes
# the word “end”, make that be the last item you print and end the loop.
# e.g. given l1 = [1, ‘a’, ‘b’, [‘c’, ‘d’, ‘e’], 4, ‘thisshouldendloop’,
7, 8]
#This should be the output:
# 1
# a
# b
# [‘c’, 4, ‘e’]
# -c
# -4
# -e
# 4
# thisshouldendloop
# Hint: use “import re” for searching if the word “end” is in contained
in any string within the outer sequence.
# Be aware to handle different cases, e.g. thisshouldendloop or
thisshouldeNdloop or thisshouldEnDloop. For handling
# the different cases, take a look at string methods as discussed in
class and above.
import re
l1 = [1, ‘a’, ‘b’, [‘c’, 4, ‘e’], 4, ‘thisshouldendloop’, 7, 8]
pass
# Question 7 (15pts)
# Write the above logic in a for loop
pass

Purchase answer to see full
attachment

error: Content is protected !!