Categories: Uncategorized

Python Programming Assignment | Online Homework Help

Instruction for this assignment will be in a word document. example for this assignment will be provided as well in a word document

QUESTION 3

Don't use plagiarized sources. Get Your Custom Essay on
Python Programming Assignment | Online Homework Help
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

#Program for various statements in python

lst = [1,3,5,7,9,”True”,76,10,11,14,”hello”,76,12,16,3,4,3,76,3]

#Print the original list
print(“Printing the original list…”)
print(str(lst))
print(“\n”)

#Append “apple” and 76 to the list
print(“Append ‘apple’ and 76 to the list…”)
print(str(lst))
lst.append(“apple”)
lst.append(76)
print(str(lst))
print(“\n”)

#Insert “cat” at position 3 in the list
print(“Insert ‘cat’ at position 3 in the list…”)
print(str(lst))
lst.insert(2, “cat”)
print(str(lst))
print(“\n”)

#Insert value 99 at the start of the list
print(“Insert value 99 at the start of the list…”)
print(str(lst))
lst.insert(0, 99)
print(str(lst))
print(“\n”)

#find the index of “hello” from the list
print(“find the index of ‘hello’ from the list…”)
helloIndex = lst.index(“hello”)
print(str(helloIndex))
print(“\n”)

#count the number of 76 in the list
print(“count the number of 76 in the list…”)
num76 = lst.count(76)
print(str(num76))
print(“\n”)

#remove the first occurence of 76 from the list
print(“remove the first occurence of 76 from the list…”)
print(str(lst))
lst.remove(76)
print(str(lst))
print(“\n”)

#Remove true from the list using pop and index
print(“Remove true from the list using pop and index…”)
print(str(lst))
trueIndex = lst.index(“True”)
popValue = lst.pop(trueIndex)
#print(str(popValue))
print(str(lst))

 

Figure 1: Question 3 output screenshot

 

QUESTION 4

#Program to create random integers and sum and get average

from __future__ import division

import random
#define the function that gets the average of a list
def listAverage(lst):
avg = 0.0
avg = sum(lst)/len(lst)
return avg

#Initialize the list
lst = []

#generate the random list of integers between 0 and 1000
for i in range(100):
num = random.randint(0, 1000)
lst.append(num)

listAverage = listAverage(lst)

#print the outcome
print(“Average of the list is: ” + str(listAverage))

 

 

Figure 2: Question 4 screenshot

 

 

 

 

 

QUESTION 10

#Program to count how many words in a list have length 5

 

#define function to get number of words of specified length in supplied list

def wordLengthCount(lst, length):
numberWord = 0
for item in lst:
if(len(item) == length):
numberWord += 1
return numberWord

#declare and initialize list of words
wordlist = [‘number’,’testing’,’words’,’five’,’seven’,’six’,’nine’,’ten’,’eight’,’sixteen’,’seventeen’,’twenty’,’twelf’]
#print the list
print(str(wordlist))

#get number of words of length 5 using the function defined above
numberWord5 = wordLengthCount(wordlist, 5)

#print the result
print(“Total number of words with length 5 is:\n” + str(numberWord5))

 

 

Figure 3: Question 10 output screenshot

 

 

 

 

QUESTION 11

#Program to sum all the elements of a list up to but not including the first even number

#define function to sum all elements up to but not including first even number of supplied list

def sum2FirstEven(lst):
sumElements = 0
numElements = 0

for item in lst:
if((item%2) == 0):
break
else:
sumElements += item
numElements += 1

#return the result as a tuple
return (numElements, sumElements)

#initialize the list to test with
testlist = [1,3,5,7,9,10,11,14,12,16]
#print the test list
print(str(testlist))

#obtain the number and sum of elements up to first even number using function defined above
(elemNum, elemSum) = sum2FirstEven(testlist)

#print the outcome
print(“Total sum of ” + str(elemNum) + ” elements is ” + str(elemSum))

 

 

Figure 4: Question 11 output screenshot

 

 

 

Suzie Mercy

Recent Posts

What is the easy difination of science | Quick Solution

Science is the pursuit and application of knowledge and understanding of the natural and social…

4 years ago

definition, values, meaning of such values and type of goods with such elasticity value …….. | Quick Solution

Clearly stating the definition, the values, the meaning of such values and the type of…

4 years ago

Acct 422 – Nora D | Quick Solution

All answered must be typed using Times New Roman (size 12, double-spaced) font. No pictures…

4 years ago

Acct 322 – Nora D | Quick Solution

All answered must be typed using Times New Roman (size 12, double-spaced) font. No pictures…

4 years ago

Macro Economics Question | Quick Solution

https://www.npr.org/sections/ed/2018/04/25/605092520/high-paying-trade-jobs-sit-empty-while-high-school-grads-line-up-for-university Click on the link above. Read the entire link and answer the questions below…

4 years ago

MGT 322 – Nora D | Quick Solution

All answered must be typed using Times New Roman (size 12, double-spaced) font. No pictures…

4 years ago