Question

In: Computer Science

Python #Exercise 1 #Assign the following first names to a variable name as a list: peter,paul,mary...

Python

#Exercise 1
#Assign the following first names to a variable name as a list: peter,paul,mary
#Assign the following last names to a variable name as a list: ng,lo,lau
#Display each first name in a separate line in turn so that your screen shows (ignore the #):
#peter
#paul
#mary
#Combine the elements in the list in turn so that you display the full names of each person in separate lines
#Output should look like the following (ignore the #):
#peter ng
#paul lo
#mary lau

#Exercise 2
#Assign the following grades to a variable name as a list: 80,90,100,70
#Use the sum() function to total up the values in the list and assign the sum to a variable
#Use the len() function to get the length of the list and assign the length to a variable
#Compute the average grade using the sum and length of the list and assign the average to a variable
#Convert the list length, list sum, and average to strings
#Display the results of your calculation in the following format using the + concatenator
#Your total score for [length of list] grades is [sum of list] resulting in an average of [average grade]!
#Ask the user for a grade using the prompt: New grade? (include a space after the ?)
#Convert the new grade into an integer
#Add the new grade to the end of the existing list using the append method
#Remove the second grade in the list using the pop method
##Use the sum() function to total up the values in the list and assign the sum to a variable
#Use the len() function to get the length of the list and assign the length to a variable
#Compute the average grade using the sum and length of the list and assign the average to a variable
#Display the results of your calculation in the following format using the + concatenator
#Your total score for [length of list] grades is [sum of list] resulting in an average of [average grade]!

#Exercise 3
#Ask the user for a student's name using the propmt: Student Name? (include a space after the ?)
#Assign the following grades to a variable name as a list: 80,90,70,85
#Assign the following requirement codes to a variable name as a list: HW,MT,IC,HW
#Ask the user for a new requirement code using the prompt: Requirement Code? (include a space after the ?)
#Ask the user for a new grade using the prompt: Grade? (include a space after the ?)
#Add the new requirement code to the requirement code list using the append method
#Convert the new grade to an integer
#Add the new grade to the end of the list of grades using the append method
#Display the following: Grades for: [student name -- input from user in first instruction of Exercise 3]
#Combine the information from both lists to display each pair of requirement code and grade in a separate line
#The output should have the following structure:
#[requirement code] [grade]
#For example, the first two lines should read (ignore the #)
#HW 80
#MT 90
#etc until the last items in the lists -- There should be 5 lines of code-grade pairings
#Get the sum of the grades list using the sum() function
#Get the length of the grades list using the len() function
#Compute the student's average grade using the sum and length
#Convert the average grade to a string
#Use the + concatenator to display the following statement (ignore the #):
#[student name]: your average grade is [average grade]!
#If student name is George Smith and average grade is 80, output should be:
#George Smith: your average grade is 80!

Solutions

Expert Solution

Excercise1:

fn=['peter','paul','mary'] //list values of first name
ln=["ng","lo","lau"]//list values of last name
print(*fn,sep="\n")

print(fn[0]+ln[0],fn[1]+ln[1],fn[2]+ln[2],sep="\n")

Excercise 2:

grades = [80,90,100,70]
def print_grades(grades):
for grade in grades:
print (grade)
print_grades(grades)
def grades_sum(scores):
total = 0
for grade in scores:
total += grade
return total
  
print (grades_sum(grades))
print("Length of grades:",len(grades))


def grades_average(grades):
sums = grades_sum(grades)
return sums / float(len(grades))
  
print (grades_average(grades))
n=int(input("Enter a new grade? "))
print(n)
grades.append(n)
print(grades)
grades.pop(1)
print(grades)
def print_grades(grades):
for grade in grades:
print (grade)
print_grades(grades)
def grades_sum(scores):
total = 0
for grade in scores:
total += grade
return total
  
print (grades_sum(grades))
print("Length of grades:",len(grades))


def grades_average(grades):
sums = grades_sum(grades)
return sums / float(len(grades))
  
print (grades_average(grades))


Related Solutions

THIS IS A PYTHON ASSIGNMENT 1. The following are invalid variable names: 3g, 87 and 2h....
THIS IS A PYTHON ASSIGNMENT 1. The following are invalid variable names: 3g, 87 and 2h. 2. The operator != is an example of a relational operator. 3. A variable name identifies the kind of information stored in the object. 4. Python treats the variable names, a1 and A1, as the same variable. 5. The if/else selection structure is a single-selection structure. 6 A fatal logic error causes a program to execute and produce incorrect results. 7) A repetition structure...
Declare a Python list named famfri with the first names of five friends or family members....
Declare a Python list named famfri with the first names of five friends or family members. Lists and tuples are examples of what kind of Python construct? Write a Python for loop that prints the names of the friends or family, one per line, without referencing a range or any literal numeric values. Write Python code examples of statements to remove the name at position 2 from the list in the first problem, and to remove one of the remaining...
By using Python code: 1. list1 = ['smith', 'john', 'andy'] list2 = ['kim', 'mary', 'paul'] Write...
By using Python code: 1. list1 = ['smith', 'john', 'andy'] list2 = ['kim', 'mary', 'paul'] Write a python program which does the following: a. add items in list2 to list1 b. Remove mary from list1 c. Insert sam at 5th position d. Sort the elements of list1 in ascending order 2. Write a python program that asks the user to enter a sentence and creates a list of words in that sentence. 3. friends = ('sam','andy','mary','andy','john','andy','mary') Write a python program...
The following is a list of the first names of 24 fictional students in a statistics...
The following is a list of the first names of 24 fictional students in a statistics class at Cleveland State University. The students are identified by numbering them 01 through 24. A sample of six students is to be selected by using systematic sampling. The first student to be selected is the one with ID 03. Choose the six students that will be included in the sample. ID Student ID Student 01 Ali 13 Sakiya 02 Pedro 14 Mary 03...
Peter and Paul bet $1 on each game. Both players start with $10. Peter is extremely...
Peter and Paul bet $1 on each game. Both players start with $10. Peter is extremely nervous on the first game, and the probability of him winning that game is only 1/4. After that, his probability of winning any given game is back to 5/8. Under these circumstances, what is the probability that Peter bankrupts Paul?
Peter and Mary take turns rolling a fair die. If Peter rolls 1 or 2 he...
Peter and Mary take turns rolling a fair die. If Peter rolls 1 or 2 he wins and the game stops. If Mary rolls 3, 4, 5, or 6, she wins and the game stops. They keep rolling in turn until one of them wins. Suppose Peter rolls first. (a) What is the probability that Peter wins? (b) What is the probability that Mary wins?
using python #You've been sent a list of names. Unfortunately, the names #come in two different...
using python #You've been sent a list of names. Unfortunately, the names #come in two different formats: # #First Middle Last #Last, First Middle # #You want the entire list to be the same. For this problem, #we'll say you want the entire list to be Last, First Middle. # #Write a function called name_refixer. name_refixer should have two #parameters: an output filename (the first parameter) and the #input filename (the second parameter). You may assume that every #line will...
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
A class Names reads the following names from the .txt file Name.txt Jason Butler Paul Cunningham...
A class Names reads the following names from the .txt file Name.txt Jason Butler Paul Cunningham Logan Bryant Cody paul Robert Vernon Ehlers III Quincy James Ellefson Currionte Evans Gavin Scott French Zach Tyler Goss Noah Cosby Jeremy Whittle Ryan brown Jonah Dalton Null Cameron jones Xavier Rhodes Malcom Wesley Jamarcus johnson Bernard smith Joseph Nettles Danny Willaims James wellington William bolar Make a search directory using dynamic allocation where the user would search the any number of letters of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT