Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

1811/2807/7001ICT Programming Principles, Trimester 1, 2021 Workshop 6 School of Information and Communication Technology Griffith University April 21, 2021 Module 2 When Workshop 6 Goals This...

1 answer below »
1811/2807/7001ICT Programming Principles, Trimester 1, 2021
Workshop 6
School of Information and Communication Technology
Griffith University
April 21, 2021
Module 2
When Workshop 6
Goals This workshop focusses on lists, indexing, slices, list methods,
and/or tuples.
Marks 5
Due Both pre-workshop and workshop tasks shall be submitted online
using the submission links. Pre-workshop questions are due before
the start of this workshop; Workshop activity problems are due
y the start of the next workshop.
1 Preparation
Before your workshop class:
ˆ Read all of this document.
ˆ Review the lecture notes sections 1 to 17.
ˆ Complete and submit the pre-workshop questions (1 mark).
ˆ Bring some paper (a print-out of this document is best) and writing implements.
ˆ Bring a storage device, such as a portable hard drive and cable, or a USB drive.
2 Electronic submission
Based on the feedback from students, we are moving to electronic submission and marking of workshops.
This means you don’t need to show your code for marking in the workshop anymore. Please submit
separate files with names “problem1.py”, “problem2.py, ..., using the submission link. Write sufficient
comments in the files to help understanding of your codes.
3 Workshop activities
3.1 Problem 1 (1 mark)
Problem: Write a program that reads strings (without digits or symbols in the string) typed
y the user until an empty string is entered. For each string, convert all words to lowercase,
then sort and print the words into descending order lexicographically.
Enter a string: Three Rings for the eleven kings under the sky
Output: under three the the sky rings kings for eleven
Enter a string: Seven for the Dwarf lords in their halls of stone
Output: their the stone seven of lords in halls for dwarf
Enter a string: Nine for Mortal Men doomed to die
Output: to nine mortal men for doomed die
1
Enter a string: One for the Dark Lord on his dark throne
Output: throne the one on lord his for dark dark
Enter a string: In the land of Mordor where the Shadows lie
Output: where the the shadows of mordor lie land in
Enter a string:
Hint: use split function to split a string into a list, then sort it with a method.
3.2 Problem 2 (1 mark)
Problem: Write a program that allows the user to enter two lists of integers, calculate the
sum of the first and the last integers in each list, and print the larger sum. In the event of a
tie, print Same. When there is only one integer in the list, the sum is the integer itself. Fo
example:
List 1: XXXXXXXXXX
List 2: 5 6 7
Output: 12
List 1: XXXXXXXXXX
List 2: 9
Output: 9
List 1: XXXXXXXXXX
List 2: XXXXXXXXXX
Output: Same
3.3 Problem 3 (1 mark)
Problem: We’ll say that a lowercase ’g’ in a string is ”happy” if there is another ’g’ immediately
to its left or right. Write a function to print True if all the g’s in the given string are happy,
otherwise, print False.
String: xggt
Happy?: True
String: abgsx
Happy?: False
String: g
Happy"? False
String:
ggsom
Happy?: True
3.4 Problem 4 (1 mark)
Problem: Write a program that allows the user to enter the marks of 5 students in 4 courses,
Output the highest average marks for students and courses. For example:
Student 1 (courses 1-4): XXXXXXXXXX
Student 2 (courses 1-4): XXXXXXXXXX
Student 3 (courses 1-4): XXXXXXXXXX
Student 4 (courses 1-4): XXXXXXXXXX
Student 5 (courses 1-4): XXXXXXXXXX
The highest average mark of students: 91.75
The highest average mark of courses: 74.2
Consider 2 dimensional lists, i.e. the element of a list is a list.
2
4 After the workshop
ˆ You have created programs that might be useful to refer back to in future workshops. Make sure
that you will have that work in the future. One copy is not enough for at IT professional. You
should have at least 2 copies:
1. on your Griffith network storage drive; and
2. on your portable storage device.
3
    Preparation
    Electronic submission
    Workshop activities
    Problem 1 (1 mark)
    Problem 2 (1 mark)
    Problem 3 (1 mark)
    Problem 4 (1 mark)
    After the workshop
Answered Same Day May 05, 2021 7001ICT Griffith University

Solution

Neha answered on May 05 2021
149 Votes
83101 - python codes/problem 1.py
#in this code we can take input from the user and it will be converted into the lower case.
string = []
userInput = input('Enter a string')
#convert user input into lower case
#convert user input into list
string = userInput.lower().split()
print(string)
#sort list in descending orde
string.sort(reverse=True)
#convert list into a string
listToStr = ' '.join([str(elem) for elem in string])
#print output
print("Output: ",listToStr)
83101 - python codes/problem 2.py
#this code will take input in two lists and show sum
#declaration for list
lst1 = []
lst2 = []
#input in first list
lst1 = input("Please enter elements for list 1: ")
#input in second list
lst2 = input("Please enter elements for list 2: ")
#sum of first elements from both the lists
sum1 = int(lst1[0]) + int(lst2[0])
#sum of last elements from both the lists
sum2 = int(lst1[-1]) + int(lst2[-1])
#if sum of first element is greater then sum of last elements then print it
if (sum1 > sum2):
print("output: ",sum1)
#else print sum of last elements.
else:
print("Output: ",sum2)
83101 - python codes/problem 3.py
#function to find it string has continous g in it.
def isHappy (userInput):
#check for first g
if 'g' in userInput:
#if found get the index value
value...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here