- 10th Jul 2024
- 17:43 pm
In this assignment, our expert will demonstrates practical Python skills through a series of exercises aimed at enhancing problem-solving abilities. Whether reversing strings or processing grades, his solutions are designed to be clear, concise, and educational. Our python experts team is dedicated to empowering learners to become proficient programmers.
Question 1: Write a python function, called reverseName(), that prompts the user to input a name and then returns the name with the alphabets reversed. For example, if the user enters the name ‘ahmed’ the function should return -> ‘demha’.
Question2: Write a python program that reads the grades for an assignment from a text file named ‘grades.txt’. The contents of the ‘grades.txt. file are given below. The program should output the average of the grades, the highest grade, and the lowest grade. The program must consist of the following methods:
a) Method getGrades(): This method reads the grades from the ‘grades.txt’ file and stores them in a list. It should also return the list with the grades.
b) Method averageGrade(): This method should return the average of all the grades.
c) Method highestGrade(): This method should return the highest grade.
d) Method lowestGrade(): This method should return the lowest grade.
Introduction To Programming - SWE 225 - Get Assignment Solution
Please note that this is a sample Introduction To Programming - SWE 225 assignment solved by our Python Experts. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- You can check the partial solution for this assignment in this blog below
Free Assignment Solution - Introduction To Programming - SWE 225
def reverse(name):
return name[::-1]
name = input("Enter the name : ")
print("Reversed name is : " + reverse(name))
#Function to read text file
def getGrades():
try:
gradeList = []
file = open("grades.txt","r")#open file in reading mode
line = file.readline()#read line from the file
while(line):#read until end of line
#extract the grade from the line
line = line.split(" ")[2]
gradeList.append(int(line))
line = file.readline()
return gradeList
except Exception as ex:
print(ex)
#function to find average of gradelist
def averageGrade(gradeList):
return sum(gradeList)/len(gradeList)
#function to find the highest grade in the list
def highestGrade(gradeList):
highest = gradeList[0]#assume first grade is highest
for i in gradeList:#iterate over the list
if i > highest:#if any grade found greater than highest
highest = i#set highest to that grade
return highest#return highest
#function to find the lowest grade in the list
def lowestGrade(gradeList):
lowest = gradeList[0]#assume first grade is lowest
for i in gradeList:#iterate over the list
if i < lowest:#if any grade found less than lowest
lowest = i#set lowest to that grade
return lowest#return lowest
gradeList = getGrades()
print("Highest Grade : ",highestGrade(gradeList))
print("Lowest Grade : ",lowestGrade(gradeList))
print("Average Grade : ",averageGrade(gradeList))
Get the best Introduction To Programming - SWE 225 assignment help and tutoring services from our experts now!
About The Author - John Smith
John Smith is a seasoned software engineer with a passion for teaching and coding. With over a decade of experience in Python programming, John has developed numerous applications and solutions for various industries. His expertise lies in creating efficient and user-friendly software, making complex concepts accessible to beginners.